Python urllib无法打开localhost

时间:2016-07-24 13:22:01

标签: python linux python-3.x raspberry-pi urllib

我在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'

1 个答案:

答案 0 :(得分:1)

在python 3中,模块是urllib.request.urlopen。使用它如下所示 -

import urllib.request
# and then 
response = urllib.request.urlopen(myurl)