About new urllib.request in python 3.1.2

pavan kumar maddali pavan_maddali at yahoo.com
Sat Jul 10 12:11:14 EDT 2010



Thank You Steve,
I am not using the urllib. I am using the xmlrpc and http modules from the 
python library.
Please see the header code for the modules I am including..

from xmlrpc import client
import pprint
class ClientCertTransport(client.Transport):
 def make_connection(self,host):
  import http
  host, extra_headers,x509 = self.get_host_info(host)
  
  try:
   HTTPS = http.HTTPS
  except AttributeError:
   raise NotImplementedError("your version of http does not support HTTPS")
  else:
   return HTTPS(host,None,'privkey.pem','resellercert.pem')

the rest of the code is just to get the result from the api....
regards
Pavan

________________________________
From: Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au>
To: python-list at python.org
Sent: Sat, July 10, 2010 11:35:06 AM
Subject: Re: About new urllib.request in python 3.1.2

On Sat, 10 Jul 2010 07:06:47 -0700, pcchen wrote:

> And for the following three simple lines of code, borrowed from official
> python-doc 3.1.2:
> 
>>>>from urllib.request import urlopen
>>>>response = urlopen('http://python.org/') html = response.read()
> 
> They could cause this error:
> 
>  File "./http.py", line 3, in <module>
>    from urllib.request import urlopen
>  File "/usr/local/lib/python3.1/urllib/request.py", line 88, in
> <module>
>    import http.client
>  File "/home/pcchen/Python/http.py", line 3, in <module>
>    from urllib.request import urlopen
> ImportError: cannot import name urlopen

Look at the traceback: your code executes "from urllib.request import 
urlopen". That line in turn executes "import http.client". And *that* 
fails, which causes the first import to fail.

It fails because you have shadowed the built-in package http with your 
own module http://http.py.

Rename your file to something else ("myhttp.py") and it should just work.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100710/b5b0153f/attachment-0001.html>


More information about the Python-list mailing list