Support bytestring URLs on Python 3.x#2238
Conversation
|
Thanks for this! I think we like the ability to pass non-strings to I think we can get around this by simply special-casing string types. The logic is really: I think that's really the logic we want here. @sigmavirus24, thoughts? |
|
I agree with @Lukasa that this is the behaviour we want. We absolutely want |
c4b735b to
9b3f3e4
Compare
|
Ah good point, forgot about that use case. |
9b3f3e4 to
aaa458d
Compare
There was a problem hiding this comment.
Would this be acceptable:
try:
url = url.decode('utf8')
except AttributeError:
url = unicode(url) if not is_py2 else str(url)There was a problem hiding this comment.
That's nice and succinct, have ammended and pushed
aaa458d to
a68d1b4
Compare
|
❤️ @buttscicles @Lukasa this looks okay to me. Thoughts? |
|
🍰 Make it so. |
|
Let's not document this :) |
Support bytestring URLs on Python 3.x
typeshed already partially reflected psf/requests#2238 but not completely.
typeshed already partially reflected psf/requests#2238 but not completely.
Hi there folks.
Currently
prepare_urlwill callunicodeorstron the url arg depending on the python version. This works fine for most cases, but the one case it trips up on is bytestrings on python 3.x as the string representation of these is"b'http://httpbin.org'". Eventually this will surface as anInvalidSchemaexception.I find this to be completely unexpected, and I'd imagine it's not something that's been done intentionally.
Technically this a breaking change. The possibility of passing non-strings to
prepare_urlis undocumented and untested, but regardless it may be better to go about fixing this in a different way, that's your call.