1

I'm working my way through The Programming Historian 2, a self-tutorial in coding for historians focusing on HTML and Python. I am attempting to complete the lesson Working with Files and Web Pages but am stuck on the Opening URLs with Python unit. I am running the following program:

# open-webpage.py

import urllib2

url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'

response = urllib2.urlopen(url)
webContent = response.read()

print webContent[0:300]

Every time I run the program Komodo Edit 7 returns the following error message:

Traceback (most recent call last):  
  File "open-webpage.py", line 7, in <module>  
    response = urllib2.urlopen(url)  
  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)  
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

I have attempted the program with a number of different urls, always with the same result. The guys at Komodo think the problem is to do with my university's firewall, because I access the internet through my university's proxy. The tech people here told me to change my default browser from RockMelt (chromium) to IE, because only IE is fully supported. I did so with no change and they have no other suggestions.

Can anyone suggest an alternate explanation for the error or a way to address the firewall problem? Thanks.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • I just tried your code and it works perfectly. So at least it's not you. :) Do you know how you access the web through the proxy? Do you have to enter any configuration or authentication in your browser? You can configure Python to do the same thing, but it's complicated if you're just getting started. It might be easier to just find a coffeeshop with wifi instead... – Rachel Sanders Nov 30 '12 at 07:26
  • Close Komodo and restart it. Does it happen every time, or not on the first run? Any chance that Komodo leaves the python interpreter alive, and when you run it again, the error actually happens in the first run or so? – Has QUIT--Anony-Mousse Nov 30 '12 at 08:01
  • @Rachel Sander: Might you be able to direct me to where I could I could learn to do that? – matthewddsg Nov 30 '12 at 16:57
  • @Anony-Mousse: As far as I can tell it does happen on the first run but I'm not sure what is means for Komodo to leave the python interpreter alive. – matthewddsg Nov 30 '12 at 16:58
  • If you're searching, try "python proxy authentication" - here's [one answer on SO](http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection) and there's also the urllib2 [documentation](http://docs.python.org/2/howto/urllib2.html#proxies). Let me know if that doesn't help and I'll see if I can find other resources. – Rachel Sanders Nov 30 '12 at 18:41
  • @RachelSanders: Thanks. I'm attempting the top answer from the SO question you linked. I'll go pester the IT people on Monday for the info I can't scrounge up and see how it goes. – matthewddsg Nov 30 '12 at 21:17

0 Answers0