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
infile = open(fname, 'rb')
content = infile.read()