Skip to content
Myr

Merge branch 'master' into patch-1

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

authored by Kenneth Reitz · committed by GitHub · parents 45c2e67, d79024f · Browse files · 20 files+62 added−51 removed
This commit

State

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

Diff stats

20 files+62 added−51 removed

  • tests:+5 added−5 removed
  • other:+57 added−46 removed

20 files+62 added−51 removed

modified:docs/_templates/sidebarintro.html+2 added-2 removed
modified:docs/community/support.rst+1 added-1 removed
27 unmodified lines
28-------------2930If you notice some unexpected behaviour in Requests, or want to see support31for a new feature,32`file an issue on GitHub <https://github.com/requests/requests/issues>`_.32`file an issue on GitHub <https://github.com/psf/requests/issues>`_.333435E-mail36------
18 unmodified lines
modified:docs/community/updates.rst+1 added-1 removed
12 unmodified lines
13GitHub14------1516The best way to track the development of Requests is through17`the GitHub repo <https://github.com/requests/requests>`_.17`the GitHub repo <https://github.com/psf/requests>`_.1819Twitter20-------21
10 unmodified lines
modified:docs/dev/contributing.rst+9 added-2 removed
128 unmodified lines
129 # Aligned with opening delimiter.130 foo = long_function_name(var_one, var_two,131 var_three, var_four)132133No. Just don't. Please.133No. Just don't. Please. This is much better::134135 foo = long_function_name(136 var_one,137 var_two,138 var_three,139 var_four,140 )141142Docstrings are to follow the following syntaxes::143144 def the_earth_is_flat():145 """NASA divided up the seas into thirty-three degrees."""
50 unmodified lines
196through the `GitHub issues`_, **both open and closed**, to confirm that the bug197hasn't been reported before. Duplicate bug reports are a huge drain on the time198of other contributors, and should be avoided as much as possible.199193.. _GitHub issues: https://github.com/requests/requests/issues200.. _GitHub issues: https://github.com/psf/requests/issues201202203Feature Requests204----------------
12 unmodified lines
modified:docs/dev/todo.rst+2 added-2 removed
6 unmodified lines
78#. Check for open issues or open a fresh issue to start a discussion around a bug.9 There is a Contributor Friendly tag for issues that should be ideal for people who are not very10 familiar with the codebase yet.11#. Fork `the repository <https://github.com/requests/requests>`_ on GitHub and start making your11#. Fork `the repository <https://github.com/psf/requests>`_ on GitHub and start making your12 changes to a new branch.13#. Write a test which shows that the bug was fixed.14#. Send a pull request and bug the maintainer until it gets merged and published. :)15 Make sure to add yourself to `AUTHORS <https://github.com/requests/requests/blob/master/AUTHORS.rst>`_.15 Make sure to add yourself to `AUTHORS <https://github.com/psf/requests/blob/master/AUTHORS.rst>`_.1617Feature Freeze18--------------19
45 unmodified lines
modified:docs/user/advanced.rst+7 added-7 removed
191 unmodified lines
192When you are using the prepared request flow, keep in mind that it does not take into account the environment.193This can cause problems if you are using environment variables to change the behaviour of requests.194For example: Self-signed SSL certificates specified in ``REQUESTS_CA_BUNDLE`` will not be taken into account.195As a result an ``SSL: CERTIFICATE_VERIFY_FAILED`` is thrown.196You can get around this behaviour by explicity merging the environment settings into your session::196You can get around this behaviour by explicitly merging the environment settings into your session::197198 from requests import Request, Session199200 s = Session()
98 unmodified lines
299immediately. You can override this behaviour and defer downloading the response300body until you access the :attr:`Response.content <requests.Response.content>`301attribute with the ``stream`` parameter::302303 tarball_url = 'https://github.com/requests/requests/tarball/master'303 tarball_url = 'https://github.com/psf/requests/tarball/master'304 r = requests.get(tarball_url, stream=True)305306At this point only the response headers have been downloaded and the connection307remains open, hence allowing us to make content retrieval conditional::
371 unmodified lines
679from GitHub. Suppose we wanted commit ``a050faf`` on Requests. We would get it680like so::681682 >>> import requests683 >>> r = requests.get('https://api.github.com/repos/requests/requests/git/commits/a050faf084662f3a352dd1a941f2c7c9f886d4ad')683 >>> r = requests.get('https://api.github.com/repos/psf/requests/git/commits/a050faf084662f3a352dd1a941f2c7c9f886d4ad')684685We should confirm that GitHub responded correctly. If it has, we want to work686out what type of content it is. Do this like so::687
46 unmodified lines
734we should probably avoid making ham-handed POSTS to it. Instead, let's play735with the Issues feature of GitHub.736737This documentation was added in response to738`Issue #482 <https://github.com/requests/requests/issues/482>`_. Given that738`Issue #482 <https://github.com/psf/requests/issues/482>`_. Given that739this issue already exists, we will use it as an example. Let's start by getting it.740741::742743 >>> r = requests.get('https://api.github.com/repos/requests/requests/issues/482')743 >>> r = requests.get('https://api.github.com/repos/psf/requests/issues/482')744 >>> r.status_code745 200746747 >>> issue = json.loads(r.text)
34 unmodified lines
782783::784785 >>> body = json.dumps({u"body": u"Sounds great! I'll get right on it!"})786 >>> url = u"https://api.github.com/repos/requests/requests/issues/482/comments"786 >>> url = u"https://api.github.com/repos/psf/requests/issues/482/comments"787788 >>> r = requests.post(url=url, data=body)789 >>> r.status_code790 404
25 unmodified lines
816 >>> print(content[u"id"])817 5804413818819 >>> body = json.dumps({u"body": u"Sounds great! I'll get right on it once I feed my cat."})820 >>> url = u"https://api.github.com/repos/requests/requests/issues/comments/5804413"820 >>> url = u"https://api.github.com/repos/psf/requests/issues/comments/5804413"821822 >>> r = requests.patch(url=url, data=body, auth=auth)823 >>> r.status_code824 200
208 unmodified lines
modified:docs/user/install.rst+4 added-4 removed
23 unmodified lines
24Get the Source Code25-------------------2627Requests is actively developed on GitHub, where the code is28`always available <https://github.com/requests/requests>`_.28`always available <https://github.com/psf/requests>`_.2930You can either clone the public repository::3132 $ git clone git://github.com/requests/requests.git32 $ git clone git://github.com/psf/requests.git3334Or, download the `tarball <https://github.com/requests/requests/tarball/master>`_::34Or, download the `tarball <https://github.com/psf/requests/tarball/master>`_::3536 $ curl -OL https://github.com/requests/requests/tarball/master36 $ curl -OL https://github.com/psf/requests/tarball/master37 # optionally, zipball is also available (for Windows users).3839Once you have a copy of the source, you can embed it in your own Python40package, or install it into your site-packages easily::
3 unmodified lines
modified:docs/index.rst+2 added-2 removed
15 unmodified lines
1617.. image:: https://img.shields.io/pypi/pyversions/requests.svg18 :target: https://pypi.org/project/requests/1920.. image:: https://codecov.io/github/requests/requests/coverage.svg?branch=master21 :target: https://codecov.io/github/requests/requests20.. image:: https://codecov.io/github/psf/requests/coverage.svg?branch=master21 :target: https://codecov.io/github/psf/requests22 :alt: codecov.io2324.. image:: https://img.shields.io/badge/Say%20Thanks!-🦉-1EAEDB.svg25 :target: https://saythanks.io/to/kennethreitz
149 unmodified lines
modified:requests/api.py+4 added-2 removed
14 unmodified lines
1516def request(method, url, **kwargs):17 """Constructs and sends a :class:`Request <Request>`.1819 :param method: method for the new :class:`Request` object.19 :param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.20 :param url: URL for the new :class:`Request` object.21 :param params: (optional) Dictionary, list of tuples or bytes to send22 in the query string for the :class:`Request`.23 :param data: (optional) Dictionary, list of tuples, bytes, or file-like
67 unmodified lines
91def head(url, **kwargs):92 r"""Sends a HEAD request.9394 :param url: URL for the new :class:`Request` object.95 :param \*\*kwargs: Optional arguments that ``request`` takes.95 :param \*\*kwargs: Optional arguments that ``request`` takes. If96 `allow_redirects` is not provided, it will be set to `False` (as97 opposed to the default :meth:`request` behavior).98 :return: :class:`Response <Response>` object99 :rtype: requests.Response100 """101
59 unmodified lines
modified:requests/auth.py+1 added-1 removed
237 unmodified lines
238 :rtype: requests.Response239 """240241 # If response is not 4xx, do not auth242 # See https://github.com/requests/requests/issues/3772242 # See https://github.com/psf/requests/issues/3772243 if not 400 <= r.status_code < 500:244 self._thread_local.num_401_calls = 1245 return r246
59 unmodified lines
modified:requests/models.py+2 added-2 removed
10 unmodified lines
11import sys1213# Import encoding now, to avoid implicit import later.14# Implicit import within threads may cause LookupError when standard library is in a ZIP,15# such as in Embedded Python. See https://github.com/requests/requests/issues/3578.15# such as in Embedded Python. See https://github.com/psf/requests/issues/3578.16import encodings.idna1718from urllib3.fields import RequestField19from urllib3.filepost import encode_multipart_formdata
337 unmodified lines
357 #: Accept objects that have string representations.358 #: We're unable to blindly call unicode/str functions359 #: as this will include the bytestring indicator (b'')360 #: on python 3.x.361 #: https://github.com/requests/requests/pull/2238361 #: https://github.com/psf/requests/pull/2238362 if isinstance(url, bytes):363 url = url.decode('utf8')364 else:365 url = unicode(url) if is_py2 else str(url)
588 unmodified lines
modified:requests/sessions.py+2 added-2 removed
190 unmodified lines
191 prepared_request.url = to_native_string(url)192193 self.rebuild_method(prepared_request, resp)194195 # https://github.com/requests/requests/issues/1084195 # https://github.com/psf/requests/issues/1084196 if resp.status_code not in (codes.temporary_redirect, codes.permanent_redirect):197 # https://github.com/requests/requests/issues/3490197 # https://github.com/psf/requests/issues/3490198 purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding')199 for header in purged_headers:200 prepared_request.headers.pop(header, None)201 prepared_request.body = None
569 unmodified lines
modified:requests/utils.py+1 added-1 removed
177 unmodified lines
178 loc = os.path.expanduser('~/{}'.format(f))179 except KeyError:180 # os.path.expanduser can fail when $HOME is undefined and181 # getpwuid fails. See https://bugs.python.org/issue20164 &182 # https://github.com/requests/requests/issues/1846182 # https://github.com/psf/requests/issues/1846183 return184185 if os.path.exists(loc):186 netrc_path = loc
791 unmodified lines
modified:tests/test_lowlevel.py+2 added-2 removed
26 unmodified lines
27def test_digestauth_401_count_reset_on_redirect():28 """Ensure we correctly reset num_401_calls after a successful digest auth,29 followed by a 302 redirect to another digest auth prompt.3031 See https://github.com/requests/requests/issues/1979.31 See https://github.com/psf/requests/issues/1979.32 """33 text_401 = (b'HTTP/1.1 401 UNAUTHORIZED\r\n'34 b'Content-Length: 0\r\n'35 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'
101 unmodified lines
137138def test_digestauth_only_on_4xx():139 """Ensure we only send digestauth on 4xx challenges.140141 See https://github.com/requests/requests/issues/3772.141 See https://github.com/psf/requests/issues/3772.142 """143 text_200_chal = (b'HTTP/1.1 200 OK\r\n'144 b'Content-Length: 0\r\n'145 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'
164 unmodified lines
modified:tests/test_requests.py+2 added-2 removed
464 unmodified lines
465466 @pytest.mark.parametrize('key', ('User-agent', 'user-agent'))467 def test_user_agent_transfers(self, httpbin, key):468469 heads = {key: 'Mozilla/5.0 (github.com/requests/requests)'}469 heads = {key: 'Mozilla/5.0 (github.com/psf/requests)'}470471 r = requests.get(httpbin('user-agent'), headers=heads)472 assert heads[key] in r.text473
1737 unmodified lines
2211 except ConnectTimeout:2212 pass22132214 def test_encoded_methods(self, httpbin):2215 """See: https://github.com/requests/requests/issues/2316"""2215 """See: https://github.com/psf/requests/issues/2316"""2216 r = requests.request(b'GET', httpbin('get'))2217 assert r.ok22182219
308 unmodified lines
modified:tests/test_utils.py+1 added-1 removed
395 unmodified lines
396 'http://example.com/fiz?buz=%25ppicture',397 ),398 ))399def test_requote_uri_with_unquoted_percents(uri, expected):400 """See: https://github.com/requests/requests/issues/2356"""400 """See: https://github.com/psf/requests/issues/2356"""401 assert requote_uri(uri) == expected402403404@pytest.mark.parametrize(
378 unmodified lines
modified:.gitignore+1 added
12 unmodified lines
13*.pyc14*.swp15*.egg16env/17.eggs/1819.workon2021t.py
5 unmodified lines
modified:AUTHORS.rst+1 added
187 unmodified lines
188- Demetrios Bairaktaris (`@DemetriosBairaktaris <https://github.com/demetriosbairaktaris>`_)189- Darren Dormer (`@ddormer <https://github.com/ddormer>`_)190- Rajiv Mayani (`@mayani <https://github.com/mayani>`_)191- Antti Kaihola (`@akaihola <https://github.com/akaihola>`_)192- "Dull Bananas" <dull.bananas0@gmail.com> (`@dullbananas <https://github.com/dullbananas>`_)
modified:HISTORY.md+10 added-10 removed
547 unmodified lines
548 status code registry.549550**Bugfixes**551552- For file-like objects that are not seeked to the very beginning, we552- For file-like objects that are not sought to the very beginning, we553 now send the content length for the number of bytes we will actually554 read, rather than the total size of the file, allowing partial file555 uploads.556- When uploading file-like objects, if they are empty or have no
235 unmodified lines
792793- Unicode URL improvements for Python 2.794- Re-order JSON param for backwards compat.795- Automatically defrag authentication schemes from host/pass URIs.796 ([\#2249](https://github.com/requests/requests/issues/2249))796 ([\#2249](https://github.com/psf/requests/issues/2249))7977982.4.2 (2014-10-05)799------------------800801**Improvements**802803- FINALLY! Add json parameter for uploads!804 ([\#2258](https://github.com/requests/requests/pull/2258))804 ([\#2258](https://github.com/psf/requests/pull/2258))805- Support for bytestring URLs on Python 3.x806 ([\#2238](https://github.com/requests/requests/pull/2238))806 ([\#2238](https://github.com/psf/requests/pull/2238))807808**Bugfixes**809810- Avoid getting stuck in a loop811 ([\#2244](https://github.com/requests/requests/pull/2244))811 ([\#2244](https://github.com/psf/requests/pull/2244))812- Multiple calls to iter\* fail with unhelpful error.813 ([\#2240](https://github.com/requests/requests/issues/2240),814 [\#2241](https://github.com/requests/requests/issues/2241))813 ([\#2240](https://github.com/psf/requests/issues/2240),814 [\#2241](https://github.com/psf/requests/issues/2241))815816**Documentation**817818- Correct redirection introduction819 ([\#2245](https://github.com/requests/requests/pull/2245/))819 ([\#2245](https://github.com/psf/requests/pull/2245/))820- Added example of how to send multiple files in one request.821 ([\#2227](https://github.com/requests/requests/pull/2227/))821 ([\#2227](https://github.com/psf/requests/pull/2227/))822- Clarify how to pass a custom set of CAs823 ([\#2248](https://github.com/requests/requests/pull/2248/))823 ([\#2248](https://github.com/psf/requests/pull/2248/))8248252.4.1 (2014-09-09)826------------------827
823 unmodified lines
modified:README.md+7 added-7 removed
2 unmodified lines
34[![image](https://img.shields.io/pypi/v/requests.svg)](https://pypi.org/project/requests/)5[![image](https://img.shields.io/pypi/l/requests.svg)](https://pypi.org/project/requests/)6[![image](https://img.shields.io/pypi/pyversions/requests.svg)](https://pypi.org/project/requests/)7[![codecov.io](https://codecov.io/github/requests/requests/coverage.svg?branch=master)](https://codecov.io/github/requests/requests)8[![image](https://img.shields.io/github/contributors/requests/requests.svg)](https://github.com/requests/requests/graphs/contributors)7[![codecov.io](https://codecov.io/github/psf/requests/coverage.svg?branch=master)](https://codecov.io/github/psf/requests)8[![image](https://img.shields.io/github/contributors/psf/requests.svg)](https://github.com/psf/requests/graphs/contributors)9[![image](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/kennethreitz)1011Requests is the only *Non-GMO* HTTP library for Python, safe for human12consumption.
18 unmodified lines
31```3233See [the similar code, sans Requests](https://gist.github.com/973705).3435[![image](https://raw.githubusercontent.com/requests/requests/master/docs/_static/requests-logo-small.png)](http://docs.python-requests.org/)35[![image](https://raw.githubusercontent.com/psf/requests/master/docs/_static/requests-logo-small.png)](http://docs.python-requests.org/)3637Requests allows you to send *organic, grass-fed* HTTP/1.1 requests,38without the need for manual labor. There's no need to manually add query39strings to your URLs, or to form-encode your POST data. Keep-alive and40HTTP connection pooling are 100% automatic, thanks to41[urllib3](https://github.com/shazow/urllib3).4243Besides, all the cool kids are doing it. Requests is one of the most44downloaded Python packages of all time, pulling in over 11,000,00044downloaded Python packages of all time, pulling in over 50,000,00045downloads every month. You don't want to be left out!4647Feature Support48---------------
43 unmodified lines
92931. Become more familiar with the project by reading our [Contributor's Guide](http://docs.python-requests.org/en/latest/dev/contributing/) and our [development philosophy](http://docs.python-requests.org/en/latest/dev/philosophy/).942. Check for open issues or open a fresh issue to start a discussion95 around a feature idea or a bug. There is a [Contributor96 Friendly](https://github.com/requests/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open)96 Friendly](https://github.com/psf/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open)97 tag for issues that should be ideal for people who are not very98 familiar with the codebase yet.993. Fork [the repository](https://github.com/requests/requests) on993. Fork [the repository](https://github.com/psf/requests) on100 GitHub to start making your changes to the **master** branch (or101 branch off of it).1024. Write a test which shows that the bug was fixed or that the feature103 works as expected.1045. Send a [pull request](https://help.github.com/en/articles/creating-a-pull-request-from-a-fork) and bug the maintainer until it gets merged and105 published. :) Make sure to add yourself to106 [AUTHORS](https://github.com/requests/requests/blob/master/AUTHORS.rst).106 [AUTHORS](https://github.com/psf/requests/blob/master/AUTHORS.rst).107