Skip to content
Myr

Merge pull request #280 from darkrho/58e018af136190a2c757b13bf9371cecc2d51273

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

Updated docs with an example of explicit filename in file uploads section

authored by Kenneth Reitz · committed by Kenneth Reitz · parents cf60062, 58e018a · Browse files · 3 files+30 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

3 files+30 added−1 removed

  • other:+30 added−1 removed

3 files+30 added−1 removed

modified:docs/user/quickstart.rst+25 added
130 unmodified lines
131 },132 "data": ""133 }134135Setting filename explicitly::136137 >>> url = 'http://httpbin.org/post'138 >>> files = {'file': ('report.xls', open('report.xls', 'rb'))}139140 >>> r = requests.post(url, files=files)141 >>> r.content142 {143 "origin": "179.13.100.4",144 "files": {145 "file": "<censored...binary...data>"146 },147 "form": {},148 "url": "http://httpbin.org/post",149 "args": {},150 "headers": {151 "Content-Length": "3196",152 "Accept-Encoding": "identity, deflate, compress, gzip",153 "Accept": "*/*",154 "User-Agent": "python-requests/0.8.0",155 "Host": "httpbin.org:80",156 "Content-Type": "multipart/form-data; boundary=127.0.0.1.502.21746.1321131593.786.1"157 },158 "data": ""159 }160161162Response Status Codes163---------------------164165We can check the response status code::
186 unmodified lines
modified:requests/api.py+1 added-1 removed
35 unmodified lines
36 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.37 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.38 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.39 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.40 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.40 :param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.41 :param auth: (optional) Auth typle to enable Basic/Digest/Custom HTTP Auth.42 :param timeout: (optional) Float describing the timeout of the request.43 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.44 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
99 unmodified lines
modified:requests/sessions.py+4 added
138 unmodified lines
139 data = {} if data is None else data140 files = {} if files is None else files141 headers = {} if headers is None else headers142 params = {} if params is None else params143 hooks = {} if hooks is None else hooks144 # use session's hooks as defaults145 for key, cb in self.hooks.iteritems():146 hooks.setdefault(key, cb)147148 # Expand header values.149 if headers:150 for k, v in headers.items() or {}:
129 unmodified lines