5 Replies - 4583 Views - Last Post: 28 December 2012 - 03:24 AM Rate Topic: -----

#1 caughtinalandslide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-December 12

Cannot get Urllib2 to work

Posted 15 December 2012 - 02:39 PM

I'm trying to run this:

 import urllib2
response = urllib2.urlopen('http://python.org/')
html = response.read()

But after executing the second line, IDLE processes something for about 15-20 seconds then shows me:

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    response=urllib2.urlopen('http://python.org/')
  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 1207, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python27\lib\urllib2.py", line 1180, in do_open
    r = h.getresponse(buffering=True)
  File "C:\Python27\lib\httplib.py", line 1030, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 365, in _read_status
    line = self.fp.readline()
  File "C:\Python27\lib\socket.py", line 447, in readline
    data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host


I'm behind no proxy or anything such. Any idea how I'm supposed to fix/debug this?

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot get Urllib2 to work

#2 caughtinalandslide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-December 12

Re: Cannot get Urllib2 to work

Posted 15 December 2012 - 02:44 PM

I'm trying this on a Windows 7 64bit PC with Python 2.7
(I couldn't figure out how to edit my main post, so I'm making a new post)
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Cannot get Urllib2 to work

Posted 15 December 2012 - 02:55 PM

No escape from reality?

I'm guessing the outbound connection is being blocked by the firewall? Works for me. May need to whitelist python.exe in the firewall settings (not running Windows, so can't give more help there).
Was This Post Helpful? 0
  • +
  • -

#4 caughtinalandslide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-December 12

Re: Cannot get Urllib2 to work

Posted 15 December 2012 - 03:06 PM

Nope it's not the firewall, just tried disabling Windows firewall completely.
Was This Post Helpful? 0
  • +
  • -

#5 caughtinalandslide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-December 12

Re: Cannot get Urllib2 to work

Posted 18 December 2012 - 07:30 AM

Any help? What else can be the cause?
Was This Post Helpful? 0
  • +
  • -

#6 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 124
  • Joined: 08-May 11

Re: Cannot get Urllib2 to work

Posted 28 December 2012 - 03:24 AM

I have no idea what the problem is. I'd reinstall python though and see if anything changes.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1