[Tutor] httplib2.RelativeURIError: Only absolute URIs are allowed. uri

pierre dagenais eq742 at ncf.ca
Mon Oct 17 00:23:45 CEST 2011


Hi,
I'm running python 3.2 on Ubuntu 11.04 and have a problem with httplib2. 
I'm not sure if it's my ignorance or a bug in the code.

This code works:

#! /usr/bin/python3.2

import urllib.request

sock = urllib.request.urlopen("file:///home/pierre/bookmarks.html")
htmlSource = sock.read()
sock.close()
print (htmlSource)


and so does this one:

#! /usr/bin/python3.2

import httplib2

h = httplib2.Http('.cache')
response, content = h.request("http://google.com")
print(response)


but this one doesn't:

#! /usr/bin/python3.2

import httplib2

h = httplib2.Http('.cache')
response, content = h.request("file:///home/pierre/bookmarks.html")
print(response)

I get this error message when I run it:

Traceback (most recent call last):
   File "Meteo5.py", line 6, in <module>
     response, content = h.request("file:///home/pierre/bookmarks.html")
   File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 984, 
in request
     (scheme, authority, request_uri, defrag_uri) = urlnorm(uri)
   File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 137, 
in urlnorm
     raise RelativeURIError("Only absolute URIs are allowed. uri = %s" % 
uri)
httplib2.RelativeURIError: Only absolute URIs are allowed. uri = 
file:///home/pierre/bookmarks.html


Isn't "file:///home/pierre/bookmarks.html" a valid URI? It works fine 
with urllib, why not with httplib2?

Your help is appreciated,


More information about the Tutor mailing list