-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
#: as this will include the bytestring indicator (b'') | ||
#: on python 3.x. | ||
#: https://github.com/kennethreitz/requests/pull/2238 | ||
if not is_py2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_url
will callunicode
orstr
on 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 anInvalidSchema
exception.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_url
is undocumented and untested, but regardless it may be better to go about fixing this in a different way, that's your call.