Skip to content
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

str() cannot handle the message which contain non-ascii characters. #180

Open
iamhappg opened this issue Jun 26, 2015 · 5 comments
Open
Labels
bug Something isn't working

Comments

@iamhappg
Copy link

[root@wrhel novnc]# /usr/bin/nova-novncproxy --web /usr/share/novnc
WebSocket server settings:

  • Listen on 10.91.32.12:6080

  • Flash security policy server

  • Web server. Web root: /usr/share/novnc

  • No SSL/TLS support (no cert file)

  • proxying from 10.91.32.12:6080 to ignore:ignore

    1: 10.91.100.1: new handler Process
    1: 10.91.100.1: "GET /vnc_auto.html?token=a4ea95cc-4de7-4c74-82bb-fb6e988139c2&title=test-002(9d848921-4632-4ca4-97ea-4c811745a57b) HTTP/1.1" 200 -
    2: 10.91.100.1: new handler Process
    3: 10.91.100.1: new handler Process
    2: 10.91.100.1: "GET /include/base.css HTTP/1.1" 200 -
    3: 10.91.100.1: "GET /include/vnc.js HTTP/1.1" 200 -
    4: 10.91.100.1: new handler Process
    5: 10.91.100.1: new handler Process
    4: 10.91.100.1: "GET /include/util.js HTTP/1.1" 200 -
    5: 10.91.100.1: "GET /include/webutil.js HTTP/1.1" 200 -
    6: 10.91.100.1: new handler Process
    7: 10.91.100.1: new handler Process
    8: 10.91.100.1: new handler Process
    6: 10.91.100.1: "GET /include/base64.js HTTP/1.1" 200 -
    9: 10.91.100.1: new handler Process
    7: 10.91.100.1: "GET /include/websock.js HTTP/1.1" 200 -
    10: 10.91.100.1: new handler Process
    11: 10.91.100.1: new handler Process
    9: 10.91.100.1: "GET /include/des.js HTTP/1.1" 200 -
    8: 10.91.100.1: "GET /include/input.js HTTP/1.1" 200 -
    10: 10.91.100.1: "GET /include/display.js HTTP/1.1" 200 -
    12: 10.91.100.1: new handler Process
    11: 10.91.100.1: "GET /include/rfb.js HTTP/1.1" 200 -
    12: 10.91.100.1: "GET /include/jsunzip.js HTTP/1.1" 200 -
    13: 10.91.100.1: new handler Process
    13: 10.91.100.1: Plain non-SSL (ws://) WebSocket connection
    13: 10.91.100.1: Version hybi-13, base64: 'True'
    13: 10.91.100.1: Path: '/websockify'
    Process Process-13:
    Traceback (most recent call last):
    File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
    self.run()
    File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
    self._target(_self._args, *_self._kwargs)
    File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 724, in top_new_client
    self.msg("handler exception: %s" % str(exc))
    File "/usr/lib/python2.6/site-packages/nova/openstack/common/gettextutils.py", line 283, in str
    raise UnicodeError(msg)
    UnicodeError: Message objects do not support str() because they may contain non-ascii characters. Please use unicode() or translate() instead.

@DirectXMan12 DirectXMan12 added bug Something isn't working python labels Jun 26, 2015
@kanaka
Copy link
Member

kanaka commented Jun 26, 2015

@iamhappg the str() calls only appear to be in the exception handler code so I think the real problem is being swallowed (i.e. exception handler throws the "str()" exception when trying to print the original exception). It appears that an odd exception object is being thrown in your context (openstack) that doesn't support conversion via str(). Can you try adding this in websocket.py before line 724 for debug?

                _, exc, _ = sys.exc_info()
+                print(exc)
                self.msg("handler exception: %s" % str(exc))

@kanaka
Copy link
Member

kanaka commented Jun 26, 2015

@DirectXMan12
Copy link
Member

I think the other issue here is that we should probably be using unicode() on Python 2 and str() on Python 3, that way exceptions with unicode messages can be printed.

@iamhappg
Copy link
Author

As I know, the user saw the bug on japanese environment.
So I think the exception included the non-ascii characters (japanese characters).

@iamhappg
Copy link
Author

To get the exception in detail, I add the debug code "import traceback" and "traceback.print_exc()"
and then I try "http://10.104.0.80:6080/vnc_auto.html" in my browser. I get the exception in details: Exception(_("Invalid Token"))

2015-07-03 11:22:22.371 18566 INFO oslo.messaging._drivers.impl_rabbit [req-dffdf2ce-71f3-4ba8-a4e9-80037b2253d5 ] Connected to AMQP server on 10.104.0.80:5671
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 877, in top_new_client
client = self.do_handshake(startsock, address)
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 812, in do_handshake
self.RequestHandlerClass(retsock, address, self)
File "/usr/lib/python2.6/site-packages/nova/console/websocketproxy.py", line 118, in init
websockify.ProxyRequestHandler.init(self, _args, *kwargs)
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 115, in init
SimpleHTTPRequestHandler.init(self, req, addr, server)
File "/usr/lib64/python2.6/SocketServer.py", line 627, in init
self.handle()
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 543, in handle
SimpleHTTPRequestHandler.handle(self)
File "/usr/lib64/python2.6/BaseHTTPServer.py", line 329, in handle
self.handle_one_request()
File "/usr/lib64/python2.6/BaseHTTPServer.py", line 323, in handle_one_request
method()
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 509, in do_GET
if not self.handle_websocket():
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 497, in handle_websocket
self.new_websocket_client()
File "/usr/lib/python2.6/site-packages/nova/console/websocketproxy.py", line 76, in new_websocket_client
raise Exception(
("Invalid Token"))
Exception: Invalid Token
Process Process-7:
Traceback (most recent call last):
File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
self._target(_self._args, *_self._kwargs)
File "/usr/lib/python2.6/site-packages/websockify/websocket.py", line 888, in top_new_client
self.msg("handler exception: %s" % strutils.safe_encode(exc))
File "/usr/lib/python2.6/site-packages/nova/openstack/common/strutils.py", line 188, in safe_encode
raise TypeError("%s can't be encoded" % type(text))
TypeError: <type 'exceptions.Exception'> can't be encoded
2015-07-03 11:22:22.400 18370 DEBUG nova.console.websocketproxy [-] Reaing zombies, active child count is 6 vmsg /usr/lib/python2.6/site-packages/websockify/websocket.py:827

@samhed samhed removed the python label Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants