-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
test_xmlrpc fails with non-ascii path #51855
Comments
I configured my buildbot to use a non-ascii path to the interpreter and ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 59091)
Traceback (most recent call last):
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/xmlrpc/server.py",
line 448, in do_POST
size_remaining = int(self.headers["content-length"])
ValueError: invalid literal for int() with base 10: 'I am broken'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/socketserver.py",
line 281, in _handle_request_noblock
self.process_request(request, client_address)
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/socketserver.py",
line 307, in process_request
self.finish_request(request, client_address)
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/socketserver.py",
line 320, in finish_request
self.RequestHandlerClass(request, client_address, self)
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/socketserver.py",
line 614, in __init__
self.handle()
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/http/server.py",
line 352, in handle
self.handle_one_request()
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/http/server.py",
line 346, in handle_one_request
method()
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/xmlrpc/server.py",
line 472, in do_POST
self.send_header("X-traceback", traceback.format_exc())
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/http/server.py",
line 410, in send_header
self.wfile.write(("%s: %s\r\n" % (keyword, value)).encode('ASCII',
'strict'))
UnicodeEncodeError: 'ascii' codec can't encode character '\u20ac' in
position 93: ordinal not in range(128)
----------------------------------------
====================================================================== Traceback (most recent call last):
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/test/test_xmlrpc.py",
line 555, in test_fail_with_info
p.pow(6,8)
xmlrpc.client.ProtocolError: <ProtocolError for 127.0.0.1:57828/RPC2:
500 Internal Server Error>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"/home/buildbot/cpython-ucs4-nonascii-€/3.1.pitrou-ubuntu-wide/build/Lib/test/test_xmlrpc.py",
line 562, in test_fail_with_info
self.assertTrue(e.headers.get("X-traceback") is not None)
AssertionError: False is not True |
That's fairly tricky. send_header expects two strings (bytes are I see two options: Not sure whether there is any precedence for UTF-8 in HTTP |
A little googling came up with this page: Their solution is to uri encode the UTF8 encoded data. However, this article references the RFCs, which look like they call for http://stackoverflow.com/questions/324470/http-headers-encoding-decoding-in-java |
If it's only about transmitting the string representation of the |
David: I think it's a little bit more complicated. RFC 2616 says that The TEXT rule is only used for descriptive field contents and values So I think send_header should change in the following way: a) if isinstance(value, bytes): send value as-is
The purpose of the algorithm in c) would be that text containing a few The same change would also apply to the client-side of sending headers.
|
Antoine: sure, to fix the issue at hand, we can work-around. However, the issue of sending non-ASCII headers in HTTP remains, and |
bpo-7608 was a duplicate issue. Copy of my message (msg98091): A simple fix would be to use the ASCII charset with the backslashreplace error handler. Attached patch uses: trace = str(trace.encode('ASCII', 'backslashreplace'), 'ASCII') Is there an easier method to escape non-ASCII characters without double conversion (unicode->bytes and bytes->unicode)? |
pitrou> If it's only about transmitting the string representation of the Both replace and ignore loose information. My patch keeps all information by using backslashreplace. It's consistent with Python behaviour: Python writes a backtrace to stderr which uses also the backslashreplace error handler. |
What do you think about my solution (convert the traceback to ASCII to avoid the encoding issue)? If you would like to support non-ASCII characters in HTTP headers, you should open a new issue. For the compatibility, I prefer to use pure ASCII headers because I fear that third party programs doesn't support non-ASCII headers. |
It's fine for me. Perhaps you should add a comment to explain why this is necessary. |
Commited: r80112 (py3k). Waiting for the buildbots before te backport to 3.1. |
Looks good: r80118 (3.1). |
If anyone would like to work on non-ASCII HTTP header, please open a new issue with a pointer to this one. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: