我已經完成了這一百萬次,但由於某種原因,我在嘗試使用urllib2時出現了一些奇怪的錯誤。我最近從Ubuntu 11.10升級到12.04。使用Python時奇怪的ImportError urllib2
代碼:
from urllib2 import urlopen
urlopen('http://www.google.com').read()
結果:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
urlopen('http://www.google.com').read()
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 400, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 418, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1146, in do_open
h = http_class(host, timeout=req.timeout) # will parse host:port
File "/home/nate/httplib.py", line 362, in __init__
ImportError: No module named appengine.api
我使用的urllib時得到了類似的錯誤。任何想法可能會導致這種情況,以及如何解決這個問題?
它不在PYTHONPATH中。它位於sys.path中的第一個當前目錄中。 – quantum
是的。感謝修正@xiaomao。 – unutbu