From 916e6fcd64d16252cb884106a0dd225a7a1c2549 Mon Sep 17 00:00:00 2001 From: Eric Scrivner Date: Mon, 17 Dec 2012 12:28:08 -0800 Subject: [PATCH 1/2] Add unit-test to reproduce encoding error. --- test_requests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test_requests.py b/test_requests.py index 61634cd1bf..e55a4cf6c3 100644 --- a/test_requests.py +++ b/test_requests.py @@ -3,6 +3,7 @@ """Tests for Requests.""" +import json import os import unittest @@ -243,7 +244,14 @@ def test_urlencoded_get_query_multivalued_param(self): self.assertEqual(r.status_code, 200) self.assertEqual(r.url, httpbin('get?test=foo&test=baz')) + def test_different_encodings_dont_break_post(self): + r = requests.post(httpbin('post'), + data={'stuff': json.dumps({'a': 123})}, + params={'blah': 'asdf1234'}, + files={'file': ('test_requests.py', open(__file__, 'rb'))}) + self.assertEqual(r.status_code, 200) + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From 8c01865d62df56a8cd9f9e776febf456d91d2010 Mon Sep 17 00:00:00 2001 From: Eric Scrivner Date: Mon, 17 Dec 2012 12:39:15 -0800 Subject: [PATCH 2/2] Remove unicode encoding for HTTP method. --- requests/models.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/requests/models.py b/requests/models.py index 14094a6cdd..372d7ce1c3 100644 --- a/requests/models.py +++ b/requests/models.py @@ -28,7 +28,7 @@ guess_json_utf) from .compat import ( cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes, - StringIO, is_py2, chardet, json, builtin_str, urldefrag, basestring) + StringIO, is_py2, is_py3, chardet, json, builtin_str, urldefrag, basestring) REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved) CONTENT_CHUNK_SIZE = 10 * 1024 @@ -222,13 +222,9 @@ def __repr__(self): def prepare_method(self, method): """Prepares the given HTTP method.""" - try: - method = unicode(method) - except NameError: - # We're on Python 3. - method = str(method) - - self.method = method.upper() + self.method = method + if self.method is not None: + self.method = self.method.upper() def prepare_url(self, url, params): """Prepares the given HTTP URL."""