2016-07-24 180 views
-3

我在Linux上使用Python 3.4.2這裏是我的代碼。Python urllib無法打開本地主機

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

['urllib.request.urlopen'](https://docs.python.org/3/library/urllib.request.html#module-urllib.request) 3 –

回答

1

在Python 3模塊是urllib.request.urlopen。使用它作爲在python所示如下─

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