Fixed issue11082 - Reject str for POST data with a TypeError. Document the need to explicitly encode to bytes when using urlencode.
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index a188393..dfdbdec 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1048,6 +1048,9 @@
if request.data is not None: # POST
data = request.data
+ if isinstance(data, str):
+ raise TypeError("POST data should be bytes"
+ " or an iterable of bytes. It cannot be str.")
if not request.has_header('Content-type'):
request.add_unredirected_header(
'Content-type',