Stack Trace for on proxy is a console application to browse Hacker News articles, but it didn't work behind a proxy server. Here's the error.

By Ryan McGreal

Posted December 07, 2009 in Projects (Last Updated January 07, 2010)


1The Stack Trace
2Update 1: Proxies With Urllib2
3Update 2: If No Proxy
4Update 3: on GitHub

1 The Stack Trace

Here's the original stack trace (Python 2.6 on a Windows XP machine behind a proxy server) for Hacker News Shell.

Traceback (most recent call last):
  File "", line 558, in 
    hnsh = HackerNewsShell()
  File "", line 314, in __init__
    self.stories = self.h.getLatestStories(self.alreadyReadList)
  File "", line 194, in getLatestStories
    source = self.getSource("")
  File "", line 35, in getSource
    f = urllib2.urlopen(url)
  File "C:\Python26\lib\", line 124, in urlopen
    return, data, timeout)
  File "C:\Python26\lib\", line 389, in open
    response = self._open(req, data)
  File "C:\Python26\lib\", line 407, in _open
    '_open', req)
  File "C:\Python26\lib\", line 367, in _call_chain
    result = func(*args)
  File "C:\Python26\lib\", line 1140, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "C:\Python26\lib\", line 1115, in do_open
    raise URLError(err)

2 Update 1: Proxies With Urllib2

After prompting the user for their proxy server, you'll probably want to do something like this:

# Example: proxies is a dict
proxies = { 'http': '' } 
proxy_support = urllib2.ProxyHandler(proxies)
opener = urllib2.build_opener(proxy_support)

This is untested, but it should work more or less as written.

3 Update 2: If No Proxy

It may be helpful to note further that you can submit an empty proxies dict in the above code if the internet connection is direct:

proxies = {}

This way, you can use the same code to connect to the URL whether or not the user is behind a proxy server.

4 Update 3: on GitHub

Scott Jackson, author of, moved the code into git and posted the repository on GitHub:

Check this out from the source code:

Special thanks to Ryan McGreal ( for the code that makes hnsh work from behind a proxy.

flushes with pride