我想在python2.7中打印url(" http://www.wdylike.appspot.com/?q=love")的输出。这是我的代码:
import urllib
def check_profanity():
connection = urllib.urlopen("http://www.wdylike.appspot.com/?q=love")
output = connection.read()
print(output)
connection.close()
check_profanity()
但是我收到了这样的错误:
Traceback (most recent call last):
File "/Users/mading/Desktop/python/Udacity/check_profanity.py", line 18, in <module>
check_profanity()
File "/Users/mading/Desktop/python/Udacity/check_profanity.py", line 12, in check_profanity
connection = urllib.urlopen("http://www.wdylike.appspot.com/?q=love")
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 882, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 844, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 821, in connect
self.timeout, self.source_address)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 60] Operation timed out