2012-12-05 67 views
0

我在這串字符串結果是URL www.test.comHTTP請求2.7.3

我知道,在www.test.com與數的網站。我將把它作爲一個整數保存在我的程序中。

import urllib 
giveTheInt = [urllib.urlopen(url)] 

但我只收到:

IOError: [Errno socket error] [Errno 110] Connection timed out. 

這是確定的無線,我到互聯網的連接。

回答

0

這是你在找什麼?

#!/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通它,那可能是您出錯的原因。

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