Reputation: 35
So, I am new to python and I am having an issue using urllib2. I had used it before and it worked fine, but I downloaded a new python version (I changed it to a 64-bit for Windows 7 because I downloaded the 32-bit on accident and could not import requests. Then realized that my laptop is 64-bit so after I changed it, I was able to import requests but then I couldn't use urllib2) and then all of a sudden I just could not get it working. Every time I try to use urllib2.urlopen('name of url').read()
, I get this error:
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>
I have to use urllib2 to start a school assignment and I have no idea how to fix this problem.
Upvotes: 0
Views: 1458
Reputation: 2868
The problem is with the URL. Use http instead of https:
page = urllib2.urlopen('http://huffingtonpost.com').read()
Upvotes: 2