[Tutor] auto referer handler/opener for urlib2?

xbmuncher xboxmuncher at gmail.com
Tue Oct 21 06:05:03 CEST 2008

I was reading about urllib2 openers.. Can I make any kind of def or function
and make the urllib2 "urlopen" function run through this function first
before opening a url? For example, something like a reporthook function.
What I want to do is this:

def autoReferer(handle):
if handle.lastRequest.url != None:
handle.addheader('referer' : handle.lastRequest.url)

How can make this auto referer functionality with urllib2?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081021/b6ebe162/attachment.htm>

More information about the Tutor mailing list