From bc5cc0dc92ae0b6edc356c90637a0d64e1d5042b Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Fri, 9 Mar 2012 17:26:57 -0500 Subject: [PATCH 1/5] potentially fixes #338 This attempts to fix an issue where encoding of a string might fail when the encoding is set to some unknown format. Here we attempt to catch the LookupException and subsequently blindly encode the string one final time. That is we call str() over response.content without specifying an encoding. This may still fail in certain cases but does properly handle the case of #338 by returning the expected string. --- requests/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requests/models.py b/requests/models.py index 753e83ab..4bccb1e3 100644 --- a/requests/models.py +++ b/requests/models.py @@ -788,6 +788,9 @@ class Response(object): # Decode unicode from given encoding. try: content = str(self.content, encoding, errors='replace') + except LookupError: + # try blindly encoding + content = str(self.content, errors='replace') except (UnicodeError, TypeError): pass From 83a9f2c7407347a4e1e148e2a1bea4b47e1543c0 Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Sun, 11 Mar 2012 22:22:29 -0400 Subject: [PATCH 2/5] explicating the cause of LookupError with a better comment --- requests/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 4bccb1e3..fa06948a 100644 --- a/requests/models.py +++ b/requests/models.py @@ -789,7 +789,10 @@ class Response(object): try: content = str(self.content, encoding, errors='replace') except LookupError: - # try blindly encoding + # A LookupError is raised if the encoding was not found which could + # indicate a misspelling or similar mistake. + # + # So we try blindly encoding. content = str(self.content, errors='replace') except (UnicodeError, TypeError): pass From 8f8062723ae75b25c6f7b1dead7a52e611734302 Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Tue, 13 Mar 2012 20:10:32 -0400 Subject: [PATCH 3/5] removing unused import --- requests/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/requests/utils.py b/requests/utils.py index 6952a996..9b78cefc 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -14,7 +14,6 @@ import codecs import os import random import re -import traceback import zlib from netrc import netrc, NetrcParseError From ee861f42873ed3b19dd382c3d6fb9e0d5a7521cf Mon Sep 17 00:00:00 2001 From: Pinkerton Date: Wed, 14 Mar 2012 19:54:06 -0700 Subject: [PATCH 4/5] Fix issue #484 --- requests/packages/oreos/monkeys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/packages/oreos/monkeys.py b/requests/packages/oreos/monkeys.py index 72ce68d3..2cf90163 100644 --- a/requests/packages/oreos/monkeys.py +++ b/requests/packages/oreos/monkeys.py @@ -255,7 +255,7 @@ class CookieError(Exception): # _RFC2965Forbidden = "[]:{}=" _LegalChars = ( string.ascii_letters + string.digits + - "!#$%&'*+-.^_`|~_" + _RFC2965Forbidden ) + "!#$%&'*+-.^_`|~_@" + _RFC2965Forbidden ) _Translator = { '\000' : '\\000', '\001' : '\\001', '\002' : '\\002', '\003' : '\\003', '\004' : '\\004', '\005' : '\\005', From a094ad8f312165b96d889cb4d24eb5954556a0db Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Thu, 15 Mar 2012 22:05:08 -0300 Subject: [PATCH 5/5] fixing link to AUTHORS in README --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ad88b42d..7ea6ab64 100644 --- a/README.rst +++ b/README.rst @@ -73,4 +73,4 @@ Contribute #. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_. .. _`the repository`: http://github.com/kennethreitz/requests -.. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS +.. _AUTHORS: https://github.com/kennethreitz/requests/blob/develop/AUTHORS.rst