2013-11-09 82 views
0

所以,我是新來的python和我有一個問題,使用urllib2。我曾經使用它,它運行良好,但我下載了一個新的Python版本(我將它更改爲64位的Windows 7,因爲我意外下載了32位,無法導入請求,然後意識到我的筆記本電腦是64位,所以我改變它後,我能夠導入請求,但後來我不能使用urllib2),然後突然間我無法正常工作。每次我嘗試使用urllib2.urlopen('name of url').read(),我得到這個錯誤:使用urllib2 python

Traceback (most recent call last): 
File "<pyshell#1>", line 1, in <module> 
    page = urllib2.urlopen('https://huffingtonpost.com').read() 
File "C:\Python27\lib\urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) 
File "C:\Python27\lib\urllib2.py", line 400, in open 
    response = self._open(req, data) 
File "C:\Python27\lib\urllib2.py", line 418, in _open 
    '_open', req) 
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain 
    result = func(*args) 
File "C:\Python27\lib\urllib2.py", line 1215, in https_open 
    return self.do_open(httplib.HTTPSConnection, req) 
File "C:\Python27\lib\urllib2.py", line 1177, in do_open 
    raise URLError(err) 
URLError: <urlopen error [Errno 10061] No connection could be made because the target machine actively refused it> 

我必須使用的urllib2開始作業,我不知道如何解決這個問題。

+0

Urllib2很費勁。改用'requests'。這是第三方,但它會讓你的生活變得更輕鬆。 – Marcin

回答

2

問題出在URL上。使用http而不是https:

page = urllib2.urlopen('http://huffingtonpost.com').read() 
+0

哦,哈哈,做到了..我不知道我怎麼看了那第二次..謝謝! – user2918801