Skip to content

Commit

Permalink
Merge pull request psf#1024 from etscrivner/master
Browse files Browse the repository at this point in the history
Fix HTTP method encoding problem with attached files
  • Loading branch information
Kenneth Reitz committed Dec 17, 2012
2 parents 4701243 + 8c01865 commit 5c4aa0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 4 additions & 8 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
10 changes: 9 additions & 1 deletion test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Tests for Requests."""

import json
import os
import unittest

Expand Down Expand Up @@ -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()
unittest.main()

0 comments on commit 5c4aa0b

Please sign in to comment.