From 44cc53578e4a5bd5122ecbcbfcf16000ed4e57fc Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 4 Jul 2014 23:36:34 +0400 Subject: [PATCH] Remove Accept-Charset even in case of error --- Robots/bkmk_rurllib.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Robots/bkmk_rurllib.py b/Robots/bkmk_rurllib.py index efade79..ceaf67b 100644 --- a/Robots/bkmk_rurllib.py +++ b/Robots/bkmk_rurllib.py @@ -81,9 +81,11 @@ class robot_urllib(robot_base): 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() -- 2.39.5