Skip to content
Myr

Merge pull request #1024 from etscrivner/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix HTTP method encoding problem with attached files

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 4701243, 8c01865 · Browse files · 2 files+13 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−9 removed

  • other:+13 added−9 removed

2 files+13 added−9 removed

modified:requests/models.py+4 added-8 removed
26 unmodified lines
27 to_key_val_list, DEFAULT_CA_BUNDLE_PATH, parse_header_links, iter_slices,28 guess_json_utf)29from .compat import (30 cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,31 StringIO, is_py2, chardet, json, builtin_str, urldefrag, basestring)31 StringIO, is_py2, is_py3, chardet, json, builtin_str, urldefrag, basestring)3233REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)34CONTENT_CHUNK_SIZE = 10 * 102435ITER_CHUNK_SIZE = 10 * 1024
185 unmodified lines
221 return '<PreparedRequest [%s]>' % (self.method)222223 def prepare_method(self, method):224 """Prepares the given HTTP method."""225 try:226 method = unicode(method)227 except NameError:228 # We're on Python 3.229 method = str(method)225 self.method = method226 if self.method is not None:227 self.method = self.method.upper()228231 self.method = method.upper()232229 def prepare_url(self, url, params):230 """Prepares the given HTTP URL."""231 #: Accept objects that have string representations.232 try:
343 unmodified lines
modified:test_requests.py+9 added-1 removed
1 unmodified line
2# -*- coding: utf-8 -*-34"""Tests for Requests."""56import json7import os8import unittest910import requests
232 unmodified lines
243 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))244 self.assertEqual(r.status_code, 200)245 self.assertEqual(r.url, httpbin('get?test=foo&test=baz'))246247 def test_different_encodings_dont_break_post(self):248 r = requests.post(httpbin('post'),249 data={'stuff': json.dumps({'a': 123})},250 params={'blah': 'asdf1234'},251 files={'file': ('test_requests.py', open(__file__, 'rb'))})252 self.assertEqual(r.status_code, 200)253254255256if __name__ == '__main__':249 unittest.main()257 unittest.main()