2238: unicode error in postreview

movieext*********@gmai***** (Google Code) (Is this you? Claim this profile.)
david
david
Jan. 8, 2013
What version are you running?

1.6 RC2

What's the URL of the page containing the problem?

This is the postreview

What steps will reproduce the problem?
1. post_review --summary="xxx" -o --revision-range=....
2. the diff contains non-ascii characters
3.

What is the expected output? What do you see instead?

Unicode error

What operating system are you using? What browser?

Linux / Ubuntu

Please provide any additional information below.

The error is in postreview.py, line 894. If the url is passed in as unicode, urlopen will convert data (which is encoded utf8) to unicode. This causes a conversion error.

The solution is to encode the url to a string before calling urlopen.

            if type(url) == unicode:                   # new code
                url = url.encode('utf8')               # new code
            r = urllib2.Request(url, body, headers)    # existing
            data = urllib2.urlopen(r).read()           # existing
chipx86
#1 chipx86
Can you show the traceback for when it fails?

I'm curious why the url of all things changes how the data is processed. Bug in Python?
  • +NeedInfo
  • +Component-RBTools
david
#2 david
  • -NeedInfo
    +Incomplete
#3 ste****@gmai***** (Google Code) (Is this you? Claim this profile.)
I can reproduce this with RBTools 0.3, Python 2.7 on OS X 10.7, but this only seems to manifest on OS X when the posted data includes unicode. We have multiple reports from Mac users on this issue since upgrading to ReviewBoard 1.6.14 (from 1.5), and the fix does address the problem.

A few of us spent a few hours trying to find out /why/ it fails this way and why the code change suggested fixes the problem, to no avail.

Traceback (most recent call last): 
File "/usr/local/bin/post-review", line 8, in <module> 
load_entry_point('RBTools==0.3.3', 'console_scripts', 'post-review')() 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 4767, in main 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 4382, in tempt_fate 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 882, in upload_diff 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 1106, in api_post 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 1088, in with_retries 
File "build/bdist.macosx-10.7-intel/egg/rbtools/postreview.py", line 1015, in http_post 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen 
return _opener.open(url, data, timeout) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 394, in open 
response = self._open(req, data) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 412, in _open 
'_open', req) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain 
result = func(*args) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1207, in https_open 
return self.do_open(httplib.HTTPSConnection, req) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1168, in do_open 
h.request(req.get_method(), req.get_selector(), req.data, headers) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request 
self._send_request(method, url, body, headers) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request 
self.endheaders(body) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders 
self._send_output(message_body) 
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 795, in _send_output 
msg += message_body 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 121630: ordinal not in range(128) 
david
#4 david
Thanks for the traceback. I'm much more confident in what's going on now.
  • -Incomplete
    +Started
  • +david
david
#5 david
Pushed the fix to rbtools master (7b53c05). Thanks!
  • -Started
    +Fixed