繁体   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