簡體   English   中英

使用urllib2 python

[英]Using urllib2 python

所以,我是python的新手,我在使用urllib2時遇到了問題。 我之前使用過它並且工作正常,但是我下載了一個新的python版本(我將其更改為64位用於Windows 7,因為我在事故中下載了32位並且無法導入請求。然后意識到我的筆記本電腦是64位所以在我改變之后,我能夠導入請求,但后來我無法使用urllib2)然后突然間我無法讓它工作。 每次我嘗試使用urllib2.urlopen('name of url').read() ,我得到這個錯誤:

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開始學校作業,我不知道如何解決這個問題。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM