[Python-ideas] Fall back to encoding unicode strings in utf-8 if latin-1 fails in http.client

Chris Angelico rosuav at gmail.com
Thu Jan 7 06:53:57 EST 2016


On Thu, Jan 7, 2016 at 10:37 PM, Paul Moore <p.f.moore at gmail.com> wrote:
>
> So IMO, this needs to be addressed as a documentation (and possibly code) fix in requests. It's something of a shame that httplib.client doesn't reject Unicode strings rather than making a silent assumption of the encoding, but that's something we have to live with for backward compatibility reasons. But there's no reason requests has to expose that behaviour to the user.
>

Personally, I would be happy with any of three behaviours:

1) Raise TypeError and demand that byte strings be used
2) Encode as UTF-8, since that's most likely to "just work", and is
also consistent
3) Encode as ASCII, and let any errors bubble up.

But, backward compat.

ChrisA


More information about the Python-ideas mailing list