miguelgrinberg / Flask-SocketIO-Chat

A simple chat application that demonstrates how to structure a Flask-SocketIO application.
http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
MIT License
676 stars 242 forks source link

I get this error when I use Hangul or Hanja characters in url. #8

Closed aceamro closed 5 years ago

aceamro commented 7 years ago

my environment python 3.5.3

pip list (Install with Flask-SocketIO-Chat/requirements.txt) appdirs (1.4.2) click (6.6) eventlet (0.17.4) Flask (0.11.1) Flask-SocketIO (2.8.5) Flask-WTF (0.9.5) greenlet (0.4.2) itsdangerous (0.24) Jinja2 (2.8) MarkupSafe (0.23) packaging (16.8) pip (9.0.1) pyparsing (2.1.10) python-engineio (1.2.4) python-socketio (1.7.1) setuptools (34.3.1) six (1.10.0) Werkzeug (0.11.10) wheel (0.29.0) WTForms (1.0.5)

I get this error when I use Hangul or Hanja characters in url. ex) http://127.0.0.1:5000/漢字 , http://127.0.0.1:5000/한글

There is no problem when using only Flask or Flask-SocketIO. Thank you.

Traceback (most recent call last): File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/eventlet/wsgi.py", line 454, in handle_one_response result = self.application(self.environ, start_response) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/flask/app.py", line 2000, in call return self.wsgi_app(environ, start_response) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/flask_socketio/init.py", line 42, in call start_response) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/engineio/middleware.py", line 49, in call return self.wsgi_app(environ, start_response) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/werkzeug/debug/init.py", line 464, in call request.path == self.console_path: File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/werkzeug/utils.py", line 73, in get value = self.func(obj) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/werkzeug/wrappers.py", line 544, in path self.charset, self.encoding_errors) File "/Users/amro/PycharmProjects/test/lib/python3.5/site-packages/werkzeug/_compat.py", line 176, in wsgi_decoding_dance return s.encode('latin1').decode(charset, errors) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1-2: ordinal not in range(256)

miguelgrinberg commented 7 years ago

This is unrelated to Flask-SocketIO, it appears to be a bug in eventlet. Just running a hello world Flask app on eventlet reproduces this problem.

You may want to report the issue, but in any case, URIs are not supposed to have Unicode characters, so they aren't really at fault for this.

aceamro commented 7 years ago

Thank you for your quick review.

I do not know if I can add any further questions here Can I see why 404 errors do not work when I add the following?

@main.errorhandler (404) def page_not_found (error):      return '404 Error Page', 404

miguelgrinberg commented 7 years ago

Try:

@main.app_errorhandler (404)
def page_not_found (error):
     return '404 Error Page', 404

You are setting the 404 handler just for the main blueprint. I'm guessing you want it to be effective for the whole application, so for that you need to use app_errorhandler.

aceamro commented 7 years ago

The issue has been resolved. Thank you very much.

StoneMoe commented 6 years ago

I get this error too, It's a eventlet problem.

Issue: https://github.com/eventlet/eventlet/issues/468

And this is a monkey patch fix: https://gist.github.com/StoneMoe/fa8b50fdb50392f2a11cef2b8d15491d

miguelgrinberg commented 5 years ago

This issue will be automatically closed due to being inactive for more than six months. Seeing that I haven't responded to your last comment, it is quite possible that I have dropped the ball on this issue and I apologize about that. If that is the case, do not take the closing of the issue personally as it is an automated process doing it, just reopen it and I'll get back to you.