我在linux上使用Python 3.4.2,下面是我的代码。
myurl = 'http://localhost/test.php'
response = urllib.urlopen(myurl)
while response.text != 'exit':
response = urllib.urlopen(myurl)
我得到了这个错误
Traceback (most recent call last) :
File "/var/www/html/led.py", line 19, in <module>
response = urllib.urlopen(myurl)
AttributeError: 'module' object has no attribute 'urlopen'
在python 3中,模块是urllib.request.urlopen
。使用如下所示-
import urllib.request
# and then
response = urllib.request.urlopen(myurl)