![](/img/trans.png)
[英]Python 2.7 cannot find module Request from urllib.request
[英]urllib.request in Python 2.7
我可以在Python 3.1中使用urllib.request模塊。 但是當我使用Python 2.7執行相同的程序時,出現了一個錯誤:
AttributeError: 'module' object has no attribute 'request'.
我相信這個錯誤是因為在urllib中沒有Python 2.7的請求模塊。 因為我需要使用tweepy,所以我必須堅持使用Python 2.7,因為tweepy不支持Python 3。
那么我如何在Python 2.7中使用urllib.request模塊呢?
也可以使用six
模塊為python2和python3制作代碼:
from six.moves import urllib
# ...
result = urllib.request.urlopen(url)
看看http://docs.python.org/library/urllib2.html 。
urllib2
模塊是urllib.request
/ urllib.error
的前身(它已被拆分為Python 3.0中的那些模塊)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.