-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
UnicodeEncodeError: 'ascii' codec can't encode characters in position 151-165: ordinal not in range(128) #1214
Comments
the method key workds is : |
That looks like an error encoding a header. Are you sending any abnormal headers on this request? Do they contain unicode strings? |
@zhguokai ping. |
I'm having the same problem. In Django, I have a view with the following method:
anexo_arquivo.nome can have the content "TAC nº 009.2016 - Mandaçaia Fest.doc". Because the unicode characters, ocoour the UnicodeEncodeError like this:
|
@rldourado it seems like you have a similar issue and from this comment it seems like @zhguokai was able to fix the issue by encoding the headers. You may also want to look at RFC 6266 and see this issue from flask. My understanding right now is that there is no bug in gunicorn here. |
@rldourado were you able to fix your issue? |
In case it's |
closing an issue as this bug happen outside of gunicorn. |
try this
|
Inspired on @codeAndxv I had to take it one step further, modifying the file name. This only avoids the problem. Also, I'm using django.
|
not correct! should use:
|
This is a bug, I should not have to use |
@x011 if your header values can be encoded as latin1, then you could upgrade to Gunicorn 20. We relaxed the strictness on header encoding in the last release. If your header values cannot be encoded as latin1, then your issue is with the HTTP specification and not Gunicorn and there is nothing we can do in Gunicorn to change it. Here is some reading if you want more information: https://dzone.com/articles/utf-8-in-http-headers |
i use nginx+gunicorn to deploay falsk app, when i accsess a method which is send_file(),an error come,the code is flow ,but it works well when i run flask standone
[2016-03-08 09:52:10 +0800] [4048] [ERROR] Error handling request /rest/api/admin/v1.2/shop/order/export
Traceback (most recent call last):
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/workers/async.py", line 52, in handle
self.handle_request(listener_name, req, client, addr)
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/workers/ggevent.py", line 163, in handle_request
super(GeventWorker, self).handle_request(*args)
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/workers/async.py", line 110, in handle_request
resp.write_file(respiter)
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/http/wsgi.py", line 396, in write_file
self.write(item)
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/http/wsgi.py", line 327, in write
self.send_headers()
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/http/wsgi.py", line 323, in send_headers
util.write(self.sock, util.to_bytestring(header_str, "ascii"))
File "/app/soft/python3.5/lib/python3.5/site-packages/gunicorn/util.py", line 508, in to_bytestring
return value.encode(encoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 151-165: ordinal not in range(128)
The text was updated successfully, but these errors were encountered: