0

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.

1
  • Urllib2 is fiddly. Use requests instead. It's third party, but it will make your life much easier. Commented Nov 9, 2013 at 17:34

1 Answer 1

2

The problem is with the URL. Use http instead of https:

page = urllib2.urlopen('http://huffingtonpost.com').read()
Sign up to request clarification or add additional context in comments.

1 Comment

oh haha that did it.. I dont know how I looked over that that second time.. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.