def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
if headers.has_key('location'):
newurl = headers['location']
def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
if headers.has_key('location'):
newurl = headers['location']
- def urlretrieve(self, bookmark, url, accept_charset=False):
+ def get(self, bookmark, url, accept_charset=False):
try:
# Set fake referer to the base URL
urllib._urlopener.addheaders[2] = ('Referer', url)
if accept_charset and bookmark.charset:
urllib._urlopener.addheader('Accept-Charset', bookmark.charset)
try:
# Set fake referer to the base URL
urllib._urlopener.addheaders[2] = ('Referer', url)
if accept_charset and bookmark.charset:
urllib._urlopener.addheader('Accept-Charset', bookmark.charset)
- fname, headers = urllib.urlretrieve(url)
- if accept_charset and bookmark.charset:
- del urllib._urlopener.addheaders[-1]
+ try:
+ fname, headers = urllib.urlretrieve(url)
+ finally:
+ if accept_charset and bookmark.charset:
+ del urllib._urlopener.addheaders[-1] # Remove Accept-Charset