Merge remote-tracking branch 'origin/develop' into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents fe7348c, e627c1f · Browse files · 4 files·+63 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+63 added−1 removed
- tests:+31 added−0 removed
- other:+32 added−1 removed
Provenance
- Commit
2a7811b- Tree
d76c3e6- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
fe7348c- Parent 2
e627c1f
4 files changed+63 added−1 removed
modified:docs/user/quickstart.rst+28 added
220 unmodified lines221 },222 "data": ""223 }224 225+Sending strings to be received as files::226 227+ >>> url = 'http://httpbin.org/post'228+ >>> files = {'file': ('report.csv', 'some,data,to,send\nanother,row,to,send\n')} 229+230+ >>> r = requests.post(url, files=files)231+ >>> r.text232+ {233+ "origin": "179.13.100.4",234+ "files": {235+ "file": "some,data,to,send\\nanother,row,to,send\\n"236+ },237+ "form": {},238+ "url": "http://httpbin.org/post",239+ "args": {},240+ "headers": {241+ "Content-Length": "216",242+ "Accept-Encoding": "identity, deflate, compress, gzip",243+ "Connection": "keep-alive",244+ "Accept": "*/*",245+ "User-Agent": "python-requests/0.11.1",246+ "Host": "httpbin.org", 247+ "Content-Type": "multipart/form-data; boundary=127.0.0.1.502.41433.1335385481.788.1"248+ }, 249+ "json": null,250+ "data": ""251+ }252+253+254 Response Status Codes255 ---------------------256 257 We can check the response status code::203 unmodified linesmodified:requests/models.py+3 added-1 removed
31 unmodified lines32 stream_decode_response_unicode, get_netrc_auth, get_environ_proxies,33 DEFAULT_CA_BUNDLE_PATH)34 from .compat import (35 cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,36- is_py2)36+ StringIO, is_py2)37 38 # Import chardet if it is available.39 try:40 import chardet307 unmodified lines348 fn, fp = v349 else:350 fn = guess_filename(v) or k351 fp = v352+ if isinstance(fp, (bytes, str)):353+ fp = StringIO(fp)354 fields.update({k: (fn, fp.read())})355 356 (body, content_type) = encode_multipart_formdata(fields)357 485 unmodified linesmodified:tests/test_requests.py+31 added
327 unmodified lines328 headers={'User-Agent': 'requests-tests'})329 330 self.assertEqual(post2.status_code, 200)331 332+ def test_POSTBIN_GET_POST_FILES_STRINGS(self):333+334+ for service in SERVICES:335+336+ url = service('post')337+338+ post1 = post(url, files={'fname.txt': 'fdata'})339+ self.assertEqual(post1.status_code, 200)340+341+ post2 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':'more fdata'})342+ self.assertEqual(post2.status_code, 200)343+344+ post3 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':open(__file__,'rb')})345+ self.assertEqual(post3.status_code, 200)346+347+ post4 = post(url, files={'fname.txt': 'fdata'})348+ self.assertEqual(post4.status_code, 200)349+350+ post5 = post(url, files={'file': ('file.txt', 'more fdata')})351+ self.assertEqual(post5.status_code, 200)352+353+ post6 = post(url, files={'fname.txt': '\xe9'})354+ self.assertEqual(post6.status_code, 200)355+356+ post7 = post(url, files={'fname.txt': 'fdata to verify'})357+ rbody = json.loads(post7.text)358+ self.assertTrue(rbody.get('files', None))359+ self.assertTrue(rbody['files'].get('fname.txt'), None)360+ self.assertEqual(rbody['files']['fname.txt'], 'fdata to verify')361+362+363 def test_nonzero_evaluation(self):364 365 for service in SERVICES:366 541 unmodified linesmodified:AUTHORS.rst+1 added
96 unmodified lines97 - Jonty Wareing <jonty@jonty.co.uk>98 - Shivaram Lingamneni99 - Miguel Turner100 - Rohan Jain (crodjer)101+- Justin Barber <barber.justin@gmail.com>