This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.parse problems with bytes vs str
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: urllib.parse: Allow bytes in some APIs that use string literals internally
View: 9873
Assigned To: Nosy List: hfuru, r.david.murray
Priority: normal Keywords: patch

Created on 2010-11-06 18:52 by hfuru, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
parse.diff hfuru, 2010-11-06 18:52 suggested urlencode simplification
Messages (2)
msg120647 - (view) Author: Hallvard B Furuseth (hfuru) Date: 2010-11-06 18:52
urlunparse(url or params = bytes object) produces a result
with the repr of the bytes object.

urllib.parse.urlunparse(['http', 'host', '/dir', b'params', '', ''])
--> "http://host/dir;b'params'"

That's confusing since urllib/parse.py goes to a lot of trouble to
support both bytes and str.  Simplest fix is to only accept str:

Index: Lib/urllib/parse.py
@@ -219,5 +219,5 @@ def urlunparse(components):
     scheme, netloc, url, params, query, fragment = components
     if params:
-        url = "%s;%s" % (url, params)
+        url = ';'.join((url, params))
     return urlunsplit((scheme, netloc, url, query, fragment))
 
Some people at comp.lang.python tell me code shouldn't anyway do str()
just in case it is needed like urllib does, not that I can make much
sense of that discussion.  (Subject: harmful str(bytes)).

BTW, the str vs bytes code doesn't have to be quite as painful as in
urllib.parse, I enclose patch which just rearranges and factors out
some code.
msg120650 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-11-06 20:30
I believe this is effectively a duplicate of issue 9873.  If not, it is still probably more appropriate to add commentary there rather than have a separate bug here.
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54552
2010-11-06 20:30:03r.david.murraysetstatus: open -> closed

superseder: urllib.parse: Allow bytes in some APIs that use string literals internally

nosy: + r.david.murray
messages: + msg120650
resolution: duplicate
stage: resolved
2010-11-06 18:52:06hfurucreate