410: post-review incorrectly handles json get request when using -r flag

mickt*****@gmai***** (Google Code) (Is this you? Claim this profile.)
Feb. 24, 2008
When updating reviews using post-review I'm getting the following error
(company specifics scrubbed):

totoro:~/src mtt$ post-review -r 31 -d
>>> Repository info 'Path: http://..., Base path: /..., Supports
changesets: False'
>>> HTTP GETting /api/json/reviewrequests/31/
Traceback (most recent call last):
  File "/Users/mtt/Applications/bin/post-review", line 893, in <module>
    main(sys.argv[1:])
  File "/Users/mtt/Applications/bin/post-review", line 875, in main
    submit_as=options.submit_as)
  File "/Users/mtt/Applications/bin/post-review", line 658, in tempt_fate
    review_request = server.get_review_request(options.rid)
  File "/Users/mtt/Applications/bin/post-review", line 141, in
get_review_request
    rsp = self.api_get('/api/json/reviewrequests/%s/' % rid)
  File "/Users/mtt/Applications/bin/post-review", line 213, in api_get
    return self.process_json(self.http_get(path))
  File "/Users/mtt/Applications/bin/post-review", line 197, in http_get
    rsp = urllib2.urlopen(url).read()
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py",
line 121, in urlopen
    return _opener.open(url, data)
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py",
line 366, in open
    protocol = req.get_type()
  File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib2.py",
line 241, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: /api/json/reviewrequests/31/

This is happening because the HTTP GET code builds the URL in a different
way to the HTTP POST code and omits the http://server prefix. I suspect
this is happening in my case because I have a server specified in my
~/.reviewboardrc without the http:// bit

I've attached a patch which uses the same code for both and allows me to
post a review update.
Index: contrib/tools/post-review
===================================================================
--- contrib/tools/post-review	(revision 1190)
+++ contrib/tools/post-review	(working copy)
@@ -191,7 +191,7 @@
         """
         debug('HTTP GETting %s' % path)
 
-        url = urljoin(self.url, path)
+        url = self._make_url(path)
 
         try:
             rsp = urllib2.urlopen(url).read()
@@ -205,6 +205,15 @@
             except AttributeError:
                 pass
             die()
+    
+    def _make_url(self, path):
+        """Given a path on the server returns a full http:// style url
+        
+        """
+        url = urljoin(self.url, path)
+        if url[0:4] != 'http':
+            url = 'http://%s' % url
+        return url
 
     def api_get(self, path):
         """
@@ -224,9 +233,7 @@
 
         if 'password' in debug_fields:
             debug_fields["password"] = "**************"
-        url = '%s%s' % (self.url, path)
-        if url[0:4] != 'http'
david
#1 david
Fixed in SVN.  Thanks!
  • +Fixed