【问题标题】:HTTP Request with Python 2.7.3使用 Python 2.7.3 的 HTTP 请求
【发布时间】:2012-11-23 07:14:25
【问题描述】:
我有一个字符串结果这个字符串是URL www.test.com
我知道 www.test.com 上有一个编号为 4 的网站。我会将程序中的数字保存为整数。
import urllib
giveTheInt = [urllib.urlopen(url)]
但我只收到:
IOError: [Errno socket error] [Errno 110] Connection timed out.
无线没问题,我有互联网连接。
【问题讨论】:
标签:
http
python-2.7
httprequest
urllib
urlopen
【解决方案1】:
我知道这是urllib2,但我看到了你的帖子,这对我有用。
#!/usr/bin/env python
import urllib2
response = urllib2.urlopen('http://ron-swanson-quotes.herokuapp.com/v2/quotes')
# print response.info()
data = response.read()
print data
response.close() # best practice to close the file
取自here。
【解决方案2】:
这是你要找的吗?
#!/usr/bin/env python
import urllib
url = "http://stackoverflow.com"
fp = urllib.urlopen(url)
data = fp.read()
n = int(data)
giveTheInt = [n]
print(giveTheInt)
您应该测试您是否可以 ping 您的whatever.com。
如果您无法 ping 它,这可能就是您出错的原因。