2515: Exception thrown when trying to post a review to an http basic auth backed instance of review board

a**@indyde****** (Google Code) (Is this you? Claim this profile.)
Nov. 19, 2013
Server setup:
- python 2.7.1
- centos 5.5

Client setup
- python 2.7.1
- rbtools 0.4.1

Note
- problem only occurs when a username is not specified on the command line or in the rc file.

post-review --parent=${review_hash}
Traceback (most recent call last):
  File "/usr/local/bin/post-review", line 9, in <module>
    load_entry_point('RBTools==0.4.1.dev', 'console_scripts', 'post-review')()
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 1222, in main
    if not server.check_api_version():
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 226, in check_api_version
    root_resource = self.api_get('api/')
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 669, in api_get
    return self.process_json(self.http_get(path))
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 639, in http_get
    rsp = urllib2.urlopen(url).read()
  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 400, in open
    response = meth(req, response)
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 97, in http_response
    response.info())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 432, in error
    result = self._call_chain(*args)
  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 884, in http_error_401
    url, req, headers)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 859, in http_error_auth_reqed
    response = self.retry_http_basic_auth(host, req, realm)
  File "/Library/Python/2.7/site-packages/RBTools-0.4.1.dev-py2.7.egg/rbtools/postreview.py", line 129, in retry_http_basic_auth
    if response.code != 401:
AttributeError: 'NoneType' object has no attribute 'code'

Git bisect led me to https://github.com/reviewboard/rbtools/commit/c27a1e2827f8b2fc7e2a0d4bf6b0e450ccb64c6a being the culprit where the realm is being compared to a hard coded string 'Web API'.
david
#1 david
  • +Component-RBTools
#2 njha****@gmai***** (Google Code) (Is this you? Claim this profile.)
The code is not checking for None return value from urllib2. One possible fix is following patch.

132c132
<             if response and response.code != 401:
---
>             if response.code != 401:
david
#3 david
This has since been fixed.
  • +Fixed
#4 huh****@gmai***** (Google Code) (Is this you? Claim this profile.)
I use this cmd to get it passed: post-review --http-username name --http-password pwd --username name --password pwd

I guess it's due to my cookie in ~/.post-review-cookies.txt is removed.