[issue26045] Improve error message for http.client when posting unicode string

2016-02-08 Thread Martin Panter
Changes by Martin Panter : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue26045] Improve error message for http.client when posting unicode string

2016-02-08 Thread Roundup Robot
Roundup Robot added the comment: New changeset 966bd147ccb5 by Martin Panter in branch '3.5': Issue #26045: Add UTF-8 suggestion to error in http.client https://hg.python.org/cpython/rev/966bd147ccb5 New changeset 9896ead3cc1d by Martin Panter in branch 'default': Issue #26045: Merge http.client

[issue26045] Improve error message for http.client when posting unicode string

2016-01-31 Thread Guido van Rossum
Guido van Rossum added the comment: LGTM. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue26045] Improve error message for http.client when posting unicode string

2016-01-31 Thread Martin Panter
Martin Panter added the comment: Here is my cut down version of Guido’s patch. Now it only adds the message when someone passes a text string as the HTTPConnection.request(body=...) parameter: >>> c.request("POST", "", body="Celebrate \U0001F389") Traceback (most recent call last): File "", l

Re: [issue26045] Improve error message for http.client when posting unicode string

2016-01-09 Thread Random832
Guido van Rossum writes: > UnicodeEncodeError: 'ascii' codec can't encode character '\u1234' in ^ ^ > position 3: Header ('ሴ') is not valid Latin-1. Use ^ ^^^ > header.encode('utf-8') if you want to send it encoded in UTF-8.

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: Martin, please make a patch along those lines! The only reason I generalized this to headers is that one of the three Requests issues referenced in the original post seemed to be about a header value (https://github.com/kennethreitz/requests/issues/1926). Bu

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Martin Panter
Martin Panter added the comment: Personally I am skeptical if suggesting UTF-8 for the body data is a good idea, but I can go along with it, since other people want it. But I do strongly question whether it is right to suggest UTF-8 for header fields. The RFC

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: I think this would be okay for 3.5.2 as well. -- versions: +Python 3.5 ___ Python tracker ___ ___

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- versions: -Python 3.2, Python 3.3, Python 3.4, Python 3.5 ___ Python tracker ___ ___ Python-bugs-list

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: BTW the error and traceback will look something like this: Traceback (most recent call last): File "", line 1, in File "/Users/guido/src/cpython/Lib/http/client.py", line 1138, in _send_request self.putheader(hdr, value) File "/Users/guido/src/cpyt

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: Here's a patch. I noticed there are lots of other places where a similar encoding() call exists -- I wrapped them all using a helper function. Please review carefully. -- keywords: +patch Added file: http://bugs.python.org/file41537/utfpatch.diff __

[issue26045] Improve error message for http.client when posting unicode string

2016-01-08 Thread Emil Stenström
Emil Stenström added the comment: I think changing the error message is enough for the short term, and deprecation of automatic encoding is the correct way in the long term. A text that mention "utf-8" which will likely be the correct solution definitely gets my vote, so Guidos suggestion soun

[issue26045] Improve error message for http.client when posting unicode string

2016-01-07 Thread Martin Panter
Martin Panter added the comment: After reading through the linked thread, there are a few error message proposals: Guido: "use data.encode('utf-8') if you want the data to be encoded in UTF-8". (Then of course the server might not like it.) Andrew Barnert: A UnicodeEncodeError (or subclass of

[issue26045] Improve error message for http.client when posting unicode string

2016-01-07 Thread Guido van Rossum
Guido van Rossum added the comment: Any solution that encodes Unicode in a way that works for some characters but fails for others has the same problem that Unicode had in Python 3. Unfortunately we're stuck with such a solution (Latin-1) and for backwards compatibility reasons we can't change

[issue26045] Improve error message for http.client when posting unicode string

2016-01-07 Thread Martin Panter
Martin Panter added the comment: For the record, this is what Requests sent when I passed a Latin-1-encodable string: b'POST / HTTP/1.1\r\n' b'Host: example.com\r\n' b'Content-Length: 11\r\n' b'Connection: keep-alive\r\n' b'Accept: */*\r\n' b'Accept-Encoding: gzip, deflate\r\n' b'User-Agent: py

[issue26045] Improve error message for http.client when posting unicode string

2016-01-07 Thread Guido van Rossum
Changes by Guido van Rossum : -- nosy: +gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue26045] Improve error message for http.client when posting unicode string

2016-01-07 Thread Emil Stenström
New submission from Emil Stenström: This issue is in response to this thread on python-ideas: https://mail.python.org/pipermail/python-ideas/2016-January/037678.html Note that Cory did a lot of encoding background work here: https://mail.python.org/pipermail/python-ideas/2016-January/037680.htm