diff options
Diffstat (limited to 'module/network/HTTPRequest.py')
-rw-r--r-- | module/network/HTTPRequest.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index 4dd41674c..ed320562d 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -205,7 +205,7 @@ class HTTPRequest(): def decodeResponse(self, rep): """ decode with correct encoding, relies on header """ header = self.header.splitlines() - encoding = None + encoding = "utf8" # default encoding for line in header: line = line.lower().replace(" ", "") @@ -214,27 +214,22 @@ class HTTPRequest(): continue none, delemiter, charset = line.rpartition("charset=") - if not delemiter: - encoding = "utf8" - else: + if delemiter: charset = charset.split(";") if charset: encoding = charset[0] - else: - encoding = "utf8" - - if encoding: - try: - #self.log.debug("Decoded %s" % encoding ) - decoder = getincrementaldecoder(encoding)("replace") - rep = decoder.decode(rep, True) - - #TODO: html_unescape as default - - except LookupError: - self.log.debug("No Decoder foung for %s" % encoding) - except Exception: - self.log.debug("Error when decoding string from %s." % encoding) + + try: + #self.log.debug("Decoded %s" % encoding ) + decoder = getincrementaldecoder(encoding)("replace") + rep = decoder.decode(rep, True) + + #TODO: html_unescape as default + + except LookupError: + self.log.debug("No Decoder foung for %s" % encoding) + except Exception: + self.log.debug("Error when decoding string from %s." % encoding) return rep |