Compare commits

...

129 Commits

Author SHA1 Message Date
Nate Prewitt
970e8cec98 v2.32.1
Some checks failed
Lint code / lint (push) Has been cancelled
Tests / build (macOS-latest, 3.10) (push) Has been cancelled
Tests / build (macOS-latest, 3.11) (push) Has been cancelled
Tests / build (macOS-latest, 3.12) (push) Has been cancelled
Tests / build (macOS-latest, 3.8) (push) Has been cancelled
Tests / build (macOS-latest, 3.9) (push) Has been cancelled
Tests / build (macOS-latest, pypy-3.10) (push) Has been cancelled
Tests / build (macOS-latest, pypy-3.9) (push) Has been cancelled
Tests / build (macos-13, 3.8) (push) Has been cancelled
Tests / build (macos-13, 3.9) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.10) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.11) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.12) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.8) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.9) (push) Has been cancelled
Tests / build (ubuntu-22.04, pypy-3.10) (push) Has been cancelled
Tests / build (ubuntu-22.04, pypy-3.9) (push) Has been cancelled
Tests / build (windows-latest, 3.10) (push) Has been cancelled
Tests / build (windows-latest, 3.11) (push) Has been cancelled
Tests / build (windows-latest, 3.12) (push) Has been cancelled
Tests / build (windows-latest, 3.8) (push) Has been cancelled
Tests / build (windows-latest, 3.9) (push) Has been cancelled
Tests / build (windows-latest, pypy-3.10) (push) Has been cancelled
Tests / build (windows-latest, pypy-3.9) (push) Has been cancelled
Tests / No Character Detection (push) Has been cancelled
2024-05-20 15:02:29 -07:00
Nate Prewitt
d6ebc4a2f1 v2.32.0
Some checks failed
Lint code / lint (push) Has been cancelled
Tests / build (macOS-latest, 3.10) (push) Has been cancelled
Tests / build (macOS-latest, 3.11) (push) Has been cancelled
Tests / build (macOS-latest, 3.12) (push) Has been cancelled
Tests / build (macOS-latest, 3.8) (push) Has been cancelled
Tests / build (macOS-latest, 3.9) (push) Has been cancelled
Tests / build (macOS-latest, pypy-3.10) (push) Has been cancelled
Tests / build (macOS-latest, pypy-3.9) (push) Has been cancelled
Tests / build (macos-13, 3.8) (push) Has been cancelled
Tests / build (macos-13, 3.9) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.10) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.11) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.12) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.8) (push) Has been cancelled
Tests / build (ubuntu-22.04, 3.9) (push) Has been cancelled
Tests / build (ubuntu-22.04, pypy-3.10) (push) Has been cancelled
Tests / build (ubuntu-22.04, pypy-3.9) (push) Has been cancelled
Tests / build (windows-latest, 3.10) (push) Has been cancelled
Tests / build (windows-latest, 3.11) (push) Has been cancelled
Tests / build (windows-latest, 3.12) (push) Has been cancelled
Tests / build (windows-latest, 3.8) (push) Has been cancelled
Tests / build (windows-latest, 3.9) (push) Has been cancelled
Tests / build (windows-latest, pypy-3.10) (push) Has been cancelled
Tests / build (windows-latest, pypy-3.9) (push) Has been cancelled
Tests / No Character Detection (push) Has been cancelled
2024-05-20 08:46:49 -07:00
agubelu
9a40d12778 Avoid reloading root certificates to improve concurrent performance (#6667) 2024-05-15 14:07:26 -06:00
Ian Stapleton Cordasco
0c030f78d2 Merge pull request #6702 from nateprewitt/no_char_detection
Allow optional char detection dependencies in post-packaging
2024-05-14 19:15:19 -05:00
Nate Prewitt
555b870eb1 Allow character detection dependencies to be optional in post-packaging steps 2024-05-14 15:26:04 -07:00
Ian Stapleton Cordasco
d6dded3f00 Merge pull request #6700 from franekmagiera/update-redirect-to-invalid-uri-test
Use an invalid URI that will not cause httpbin to throw 500
2024-05-12 16:33:47 -05:00
franekmagiera
bf24b7d8d1 Use an invalid URI that will not cause httpbin to throw 500 2024-05-12 22:08:24 +02:00
Nate Prewitt
2d5f54779a Pin 3.8 and 3.9 runners back to macos-13 (#6688) 2024-04-23 10:50:19 -07:00
Nate Prewitt
f1bb07d39b Merge pull request #6687 from psf/dependabot/github_actions/github/codeql-action-3.25.0
Bump github/codeql-action from 3.24.0 to 3.25.0
2024-04-15 11:01:39 -06:00
dependabot[bot]
60047ade64 Bump github/codeql-action from 3.24.0 to 3.25.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.24.0 to 3.25.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](e8893c57a1...df5a14dc28)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-15 16:40:35 +00:00
Ian Stapleton Cordasco
31ebb8102c Merge pull request #6682 from frenzymadness/pytest8
Fix compatibility with pytest 8
2024-04-11 14:49:35 -05:00
Lumir Balhar
cc23d1c644 Fix compatibility with pytest 8
`pytest.warns(None)` has been deprecated in pytest 7.0.0
and it's no longer working in pytest 8.

Resolves: https://github.com/psf/requests/issues/6679
2024-04-11 21:10:36 +02:00
Nate Prewitt
0790ea4250 Merge pull request #6680 from mbeijen/rfc9110
Add rfc9110 HTTP status code names
2024-04-11 07:10:57 -07:00
Michiel W. Beijen
e45b428960 Add rfc9110 HTTP status code names
RFC 9110 _HTTP Semantics_ obsoletes some earlier RFCs which defined HTTP
1.1. It adds some status codes that were previously only used for
WebDAV to HTTP _proper_ after making the names somewhat more generic.

See https://www.rfc-editor.org/rfc/rfc9110.html#name-changes-from-rfc-7231

This commit adds the http status code names from that RFC.
2024-04-08 21:48:24 +02:00
Nate Prewitt
2a438c27b5 Merge pull request #6677 from psf/dependabot/github_actions/actions/setup-python-5.1.0
Bump actions/setup-python from 5.0.0 to 5.1.0
2024-04-01 10:36:47 -07:00
dependabot[bot]
2daa7b52a7 Bump actions/setup-python from 5.0.0 to 5.1.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.0.0 to 5.1.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](0a5c615913...82c7e631bb)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-01 17:00:20 +00:00
Ian Stapleton Cordasco
8dd3b26bf5 Merge pull request #6302 from flysee/main
Fix the proxy_bypass_registry function all returning true in some cases.
2024-03-18 16:38:16 -05:00
flysee
13d892bdbe Additional should_bypass_proxies function test cases 2024-03-18 22:33:17 +08:00
flysee
1604e20fc8 Fix the proxy_bypass_registry function all returning true in some cases. 2024-03-18 15:36:36 +08:00
Ian Stapleton Cordasco
eeafb6ab3a Merge pull request #6662 from sigmavirus24/fix-tls-floppy
Add local TLS server
2024-03-14 06:25:24 -05:00
Ian Stapleton Cordasco
a94e9b5308 Add local TLS server
This also adds certificates for testing purposes and files to make it
easy to generate/regenerate them.

This also replaces an existing test of how we utilize our pool manager
such that we don't connect to badssl.com

Finally, this adds additional context parameters for our pool manager to
account for mTLS certificates used by clients to authenticate to a
server.
2024-03-14 06:06:22 -05:00
Ian Stapleton Cordasco
a58d7f2ffb Merge pull request #6655 from sigmavirus24/fix-tls-floppy
Use TLS settings in selecting connection pool
2024-03-11 06:21:59 -05:00
Ian Stapleton Cordasco
c0813a2d91 Use TLS settings in selecting connection pool
Previously, if someone made a request with `verify=False` then made a
request where they expected verification to be enabled to the same host,
they would potentially reuse a connection where TLS had not been
verified.

This fixes that issue.
2024-03-06 11:28:13 -06:00
Ian Stapleton Cordasco
eea3bbf9ac Merge pull request #6562 from amkarn258/issue-6223
every chardet package maps to requests.packages.chardet.* package respectively
2024-02-23 06:26:38 -06:00
Ian Stapleton Cordasco
f3f2611d83 Merge pull request #6583 from EFord36/fix-broken-links
Fix broken links in docs
2024-02-23 05:30:46 -06:00
Elliot Ford
a0e79bad05 update broken rfc link
ietf seems appropriate here - it's used elsewhere in the requets docs in
several places.
2024-02-23 10:26:21 +00:00
Elliot Ford
0a7f662aa7 Make example URL format a literal rather than an actual link
The rendered docs 'auto-link' this, which might encourage users to click
the link, even though it doesn't go anywhere.
2024-02-23 10:26:21 +00:00
Elliot Ford
5f1c3c22ff remove section with broken link to survey 2024-02-23 10:26:21 +00:00
Elliot Ford
541aa80ca3 update urllib3 docs link 2024-02-23 10:26:21 +00:00
Elliot Ford
d3b3399ece update authors github link
Update account link for original author which has changed.
2024-02-23 10:25:50 +00:00
Elliot Ford
0ec2780c29 update broken github pagination link 2024-02-23 10:25:50 +00:00
Ian Stapleton Cordasco
b8be93a721 Merge pull request #6589 from bruceadams/super_len_str_utf-8
Enhance `super_len` to count encoded bytes for str
2024-02-22 18:53:25 -06:00
Ian Stapleton Cordasco
3587a5f869 Merge pull request #6644 from sigmavirus24/bug/6643
Trim excess leading path separators
2024-02-22 18:49:42 -06:00
Ian Stapleton Cordasco
60389df6d6 Trim excess leading path separators
A URL with excess leading / (path-separator)s would cause urllib3 to
attempt to reparse the request-uri as a full URI with a host and port.
This bypasses that logic in ConnectionPool.urlopen by replacing these
leading /s with just a single /.

Closes #6643
2024-02-22 18:36:44 -06:00
Nate Prewitt
382fc2c0c6 Merge pull request #6629 from Tarty/fix-6628-jsondecode-error-not-deserializable
Fix #6628 - JSONDecodeError are not deserializable
2024-02-22 12:27:37 -08:00
Nate Prewitt
7a13c041db Merge pull request #6642 from nateprewitt/drop_python_37
Drop support for CPython 3.7
2024-02-20 15:44:43 -08:00
Nate Prewitt
58cea7a728 Drop support for CPython 3.7 2024-02-20 15:37:46 -08:00
Ian Stapleton Cordasco
9439fad038 Merge pull request #6641 from nateprewitt/fix_ci
Fix CI
2024-02-20 17:32:57 -06:00
Nate Prewitt
8fa4302322 Update Sphinx to work with latest readthedocs requirements 2024-02-20 15:04:38 -08:00
Nate Prewitt
28855fd43a Update supported copies of PyPy
Dropped support for pypy-3.7 and pypy-3.8 which are no longer maintained by upstream.
Added support for pypy-3.10.
2024-02-20 13:58:26 -08:00
Nate Prewitt
5fc10bf1f5 Fix httpbin pin for test suite 2024-02-20 13:37:25 -08:00
Ian Stapleton Cordasco
46c1a3d8c8 Merge pull request #6640 from nateprewitt/community_docs_cleanup
Cleanup defunct links from community docs page
2024-02-20 14:04:33 -06:00
Nate Prewitt
6106a63eb6 Cleanup defunct links from community docs page 2024-02-20 11:58:35 -08:00
Ian Stapleton Cordasco
4f3f189d6b Merge pull request #6632 from psf/dependabot/github_actions/github/codeql-action-3.24.0
Bump github/codeql-action from 3.23.0 to 3.24.0
2024-02-05 20:54:26 -06:00
dependabot[bot]
a5a0e4b587 Bump github/codeql-action from 3.23.0 to 3.24.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.23.0 to 3.24.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](e5f05b81d5...e8893c57a1)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-05 16:38:01 +00:00
Thomas Dehghani
3ff3ff21dd Fix #6628 - JSONDecodeError are not deserializable
requests.exceptions.JSONDecodeError are not deserializable: calling
`pickle.dumps` followed by `pickle.loads` will trigger an error.

This is particularly a problem in a process pool, as an attempt to
decode json on an invalid json document will result in the entire
process pool crashing.

This is due to the MRO of the `requests.exceptions.JSONDecodeError`
class: the `__reduce__` method called when pickling an instance is not
the one from the JSON library parent: two out of three args expected
for instantiation will be dropped, and the instance can't be
deserialised.

By specifying in the class which parent `__reduce__` method should be
called, the bug is fixed as all args are carried over in the resulting
pickled bytes.
2024-01-31 17:13:53 +01:00
Ian Stapleton Cordasco
96b22fa18c Merge pull request #6619 from psf/dependabot/github_actions/github/codeql-action-3.23.0
Bump github/codeql-action from 3.22.11 to 3.23.0
2024-01-08 11:56:01 -06:00
dependabot[bot]
b0e6c9bf85 Bump github/codeql-action from 3.22.11 to 3.23.0
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.22.11 to 3.23.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](b374143c11...e5f05b81d5)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-08 17:01:37 +00:00
Ian Stapleton Cordasco
72eccc8dd8 Merge pull request #6612 from miketheman/fix-docs-urls
docs: specify sphinx dirhtml builder, use references instead of absolutes
2023-12-23 12:33:48 -06:00
Mike Fiedler
25939d8784 add myself
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2023-12-23 18:15:33 +00:00
Mike Fiedler
bfba9dc68c docs: replace concrete URLs with references
Any development links will now refer back to the generated docs.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2023-12-23 18:09:55 +00:00
Mike Fiedler
f23346a9b8 Revert "Merge pull request #6605 from jaikishpai/fix-#6604"
This reverts commit 1396eb6f7a, reversing
changes made to e4c821a247.
2023-12-23 17:36:34 +00:00
Ian Stapleton Cordasco
f3f9784419 Merge pull request #6613 from miketheman/add-socks-label
docs: add label to socks heading
2023-12-23 11:24:56 -06:00
Mike Fiedler
b5bd0f14cc docs: add label to socks heading
When trying to link via intersphinx, a label must be used.
Otherwise a full URL is required, which is less desirable.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2023-12-23 17:17:34 +00:00
Mike Fiedler
242d3113c0 docs: specify sphinx dirhtml builder
With the requirement of a configuration file, the default builder
of `dirhtml` that RTD used to use is no longer specified.
This leads to URLs ending in `.html` now, which
breaks other exisitng references.

Refs: #6603
Refs: https://docs.readthedocs.io/en/stable/config-file/v2.html#sphinx-builder
Refs: https://www.sphinx-doc.org/en/master/usage/builders/index.html#sphinx.builders.dirhtml.DirectoryHTMLBuilder

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
2023-12-23 16:16:50 +00:00
Nate Prewitt
1396eb6f7a Merge pull request #6605 from jaikishpai/fix-#6604
fix for ##6604
2023-12-19 22:17:55 -08:00
Nate Prewitt
e4c821a247 Merge pull request #6607 from psf/dependabot/github_actions/github/codeql-action-3.22.11
Bump github/codeql-action from 2.22.1 to 3.22.11
2023-12-18 09:30:42 -08:00
dependabot[bot]
421b1f1757 Bump github/codeql-action from 2.22.1 to 3.22.11
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.22.1 to 3.22.11.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](fdcae64e14...b374143c11)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 16:39:47 +00:00
Jaikish Pai
1447bccc05 fix for ##6604 2023-12-17 22:34:30 +01:00
Ian Stapleton Cordasco
3b5978fc5d Merge pull request #6592 from atatuzuner61/bug/6584
"TOO_EARLY" type definition for status code 425
2023-12-16 14:24:02 -06:00
Ian Stapleton Cordasco
1ddf014f47 Merge pull request #6600 from MestreLion/MestreLion-connection-timeout-note
Add note on connection timeout being larger than specified. Fix #5773
2023-12-16 07:30:18 -06:00
Ian Stapleton Cordasco
92f9e431c9 Update docs/user/advanced.rst
Add note about wall clock too
2023-12-16 07:29:50 -06:00
Ian Stapleton Cordasco
951dd15fa6 Update docs/user/advanced.rst
fix indentation for note so it renders properly
2023-12-16 07:26:23 -06:00
Ian Stapleton Cordasco
51d0d83eaf Merge pull request #6603 from nsoranzo/rtd_config
Add now mandatory readthedocs config file
2023-12-16 07:24:37 -06:00
Nicola Soranzo
c7c2ebf1a7 Add now mandatory readthedocs config file
Docs builds currently fail with:

```
Problem in your project's configuration. No default configuration file found at repository's root. See https://docs.readthedocs.io/en/stable/config-file/
```

See e.g. https://readthedocs.org/projects/requests/builds/22842479/
2023-12-15 20:59:56 +00:00
Rodrigo Silva
a64f32ba45 Add note on connection timeout being larger than specified. Fix #5773
On servers with multiple IPs, such as IPv4 and IPv6, `urllib3` tries each address sequentially until one successfully connects, using the specified timeout for _each_ attempt, leading to a total connection timeout that is a _multiple_ of the requested time.
2023-12-13 10:05:12 -03:00
Nate Prewitt
a25fde6989 Merge pull request #6599 from psf/dependabot/github_actions/actions/setup-python-5.0.0 2023-12-11 08:11:07 -08:00
dependabot[bot]
ba67dc8dcc Bump actions/setup-python from 4.7.0 to 5.0.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.7.0 to 5.0.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](61a6322f88...0a5c615913)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 16:07:15 +00:00
Nate Prewitt
769bc3ae5c Merge pull request #6596 from psf/fix-autoclose-automtaion
Update close-issues.yml
2023-12-01 09:18:02 -08:00
Ian Stapleton Cordasco
d6ffd868ee Update close-issues.yml
I noticed the auto-labeling was working but not the auto-closing. Looking at recent actions runs I see that we need to specify the token even if we're not giving our own special token. See https://github.com/psf/requests/actions/runs/7057701782/job/19211845073#step:2:13 for additional context, namely

```
 gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable. Example:
  env:
    GH_TOKEN: ${{ github.token }}
```
2023-12-01 08:05:59 -06:00
Bruce Adams
3fd309a5c1 Enhance super_len to count encoded bytes for str
This fixes issue #6586
2023-11-29 15:42:57 -05:00
Ata Tuzuner
ec84f2c539 Fixes to test 2023-11-29 12:27:18 -05:00
Ata Tuzuner
889910c77a Added tests for status code 425 definitions. 2023-11-29 12:24:15 -05:00
Ata Tuzuner
b37878d340 Too early definition added to 425 status code type 2023-11-28 18:12:22 -05:00
Bruce Adams
f6707042d8 Unit test for string containing multi-byte UTF-8
There are two tests here. One demonstrating existing, correct
behavior for `data=bytes`, and another, failing, test for the case
where `data=string` and the string contains multi-byte UTF-8.
2023-11-27 17:27:43 -05:00
Ian Stapleton Cordasco
0b4d494192 Merge pull request #6581 from EFord36/typo-fix
fix docstring typo: a -> as
2023-11-22 09:10:47 -06:00
Elliot Ford
15849947ec fix docstring typo: a -> as 2023-11-22 11:34:04 +00:00
Ian Stapleton Cordasco
c6de5a14e5 Merge pull request #6580 from psf/dependabot/github_actions/dessant/lock-threads-5.0.0
Bump dessant/lock-threads from 4.0.1 to 5.0.0
2023-11-20 10:37:07 -06:00
dependabot[bot]
e66a07b286 Bump dessant/lock-threads from 4.0.1 to 5.0.0
Bumps [dessant/lock-threads](https://github.com/dessant/lock-threads) from 4.0.1 to 5.0.0.
- [Release notes](https://github.com/dessant/lock-threads/releases)
- [Changelog](https://github.com/dessant/lock-threads/blob/main/CHANGELOG.md)
- [Commits](be8aa5be94...d42e5f4980)

---
updated-dependencies:
- dependency-name: dessant/lock-threads
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-20 16:28:17 +00:00
Nate Prewitt
9e98a8749a Merge pull request #6574 from msea1/matthew/fix_space 2023-11-15 23:44:49 -08:00
Matthew Carruth
c32b046243 Fix missing space in error message 2023-11-15 17:00:28 -08:00
mayank
89cde235be checkstyle 2023-11-04 23:20:21 +05:30
amkarn258
d7490c9d2d Update src/requests/packages.py
Co-authored-by: Ian Stapleton Cordasco <graffatcolmingov@gmail.com>
2023-10-31 22:36:39 +05:30
mayank
e9b1217cff added handling for chardet and charset_normalizer imports 2023-10-31 20:37:59 +05:30
mayank
ad761abcdd every chardet package maps to requests.packages.chardet.* package respectively 2023-10-31 00:50:10 +05:30
Nate Prewitt
839a8edec3 Merge pull request #6552 from swims-hjkl/issue/test_header_validation
#6551  - assert statements for test test_header_validation
2023-10-17 23:08:52 -07:00
sumedhrao7
a8e9c1b436 added assert statements into tests/test_requests/test_header_validation in regards to the issue #6551 2023-10-18 07:40:50 +05:30
Nate Prewitt
b55bb15c35 Merge pull request #6527 from sigmavirus24/update-templates
Autoclose specific issue templates
2023-10-11 09:29:20 -07:00
Ian Stapleton Cordasco
8187768622 Update close-issues.yml
Remove references to GITHUB_TOKEN/MY_TOKEN
2023-10-11 08:19:57 -05:00
Ian Stapleton Cordasco
f75b9504fc Update close comment
Co-authored-by: Nate Prewitt <nate.prewitt@gmail.com>
2023-10-11 08:19:14 -05:00
Nate Prewitt
8199a2b389 Merge pull request #6548 from psf/dependabot/github_actions/github/codeql-action-2.22.1
Bump github/codeql-action from 2.21.3 to 2.22.1
2023-10-09 09:49:28 -07:00
dependabot[bot]
42a3b5cce8 Bump github/codeql-action from 2.21.3 to 2.22.1
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.21.3 to 2.22.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](5b6282e01c...fdcae64e14)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-09 16:29:55 +00:00
Nate Prewitt
f5a7aefc2d Fix urllib3 pin in setup.cfg (#6545) 2023-10-06 16:34:24 -06:00
Nate Prewitt
ee93fac6b2 Merge pull request #6538 from psf/dependabot/github_actions/actions/checkout-4.1.0
Bump actions/checkout from 4.0.0 to 4.1.0
2023-09-25 11:30:05 -07:00
dependabot[bot]
a775435c4b Bump actions/checkout from 4.0.0 to 4.1.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](3df4ab11eb...8ade135a41)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 16:28:35 +00:00
Ian Stapleton Cordasco
6c8d9b1d0f Autoclose specific issue templates
We spend a fair amount of time closing issues because people don't read
the template closely or understand what they're being told. Let's take
advantage of being able to auto-label an issue based on the template and
then trigger a workflow to auto-magically close the issue with a message
and lock the issue.
2023-09-13 09:33:58 -05:00
Ian Stapleton Cordasco
881281250f Merge pull request #6519 from psf/dependabot/github_actions/actions/checkout-4.0.0
Bump actions/checkout from 3.6.0 to 4.0.0
2023-09-04 19:17:08 -05:00
dependabot[bot]
29fc8d1e93 Bump actions/checkout from 3.6.0 to 4.0.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](f43a0e5ff2...3df4ab11eb)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 16:21:27 +00:00
Ian Stapleton Cordasco
8b560ecb24 Merge pull request #6517 from jnhyperion/remove-pytest-ini
Remove pytest.ini in MANIFEST.in since it does not exist anymore
2023-08-29 09:27:10 -05:00
Johnny.H
4585a7fbda remove pytest.ini since it does not exist anymore 2023-08-29 13:41:49 +08:00
Ian Stapleton Cordasco
16dc70df34 Merge pull request #6516 from psf/dependabot/github_actions/actions/checkout-3.6.0
Bump actions/checkout from 3.5.3 to 3.6.0
2023-08-28 14:05:56 -05:00
dependabot[bot]
bea231b033 Bump actions/checkout from 3.5.3 to 3.6.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](c85c95e3d7...f43a0e5ff2)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-28 16:12:37 +00:00
13steinj
2ee5b0b01c Fix documentation monthly download badge (#6508) 2023-08-18 11:01:26 -06:00
Jonas Schell
89f0eb91b3 fix monthly download badge (#6507) 2023-08-16 08:16:53 -07:00
Nate Prewitt
005571d118 Remove pytest-mock requirement (#6505) 2023-08-13 16:08:21 -07:00
Nate Prewitt
d63e94f552 Move to src directory (#6506) 2023-08-13 14:46:13 -07:00
Nate Prewitt
e9fa2e2da3 Add 3.12 classifier and tox configuration (#6503) 2023-08-13 12:56:18 -07:00
Nate Prewitt
678fca8423 Upgrade to httpbin 0.10.0 (#6496) 2023-08-13 09:56:53 -07:00
Nate Prewitt
d8152769ce Merge pull request #6501 from psf/dependabot/github_actions/actions/checkout-3.5.3 2023-08-12 13:15:39 -07:00
Nate Prewitt
9ff1a25ef5 Merge pull request #6502 from psf/dependabot/github_actions/github/codeql-action-2.21.3
Bump github/codeql-action from 1.1.39 to 2.21.3
2023-08-12 12:50:52 -07:00
dependabot[bot]
4bd06cd325 Bump actions/checkout from 2.7.0 to 3.5.3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.7.0 to 3.5.3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.7.0...c85c95e3d7251135ab7dc9ce3241c5835cc595a9)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-12 19:37:22 +00:00
Nate Prewitt
09a241f59e Merge pull request #6500 from psf/dependabot/github_actions/actions/setup-python-4.7.0
Bump actions/setup-python from 2.3.4 to 4.7.0
2023-08-12 12:36:48 -07:00
Nate Prewitt
6ad493650c Merge pull request #6499 from psf/dependabot/github_actions/dessant/lock-threads-4.0.1
Bump dessant/lock-threads from 3.0.0 to 4.0.1
2023-08-12 12:24:59 -07:00
dependabot[bot]
9acca90bf6 Bump github/codeql-action from 1.1.39 to 2.21.3
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1.1.39 to 2.21.3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](231aa2c8a8...5b6282e01c)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-12 19:03:30 +00:00
dependabot[bot]
c7933453cf Bump actions/setup-python from 2.3.4 to 4.7.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2.3.4 to 4.7.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2.3.4...61a6322f88396a6271a6ee3565807d608ecaddd1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-12 19:03:22 +00:00
dependabot[bot]
ea49261a27 Bump dessant/lock-threads from 3.0.0 to 4.0.1
Bumps [dessant/lock-threads](https://github.com/dessant/lock-threads) from 3.0.0 to 4.0.1.
- [Release notes](https://github.com/dessant/lock-threads/releases)
- [Changelog](https://github.com/dessant/lock-threads/blob/main/CHANGELOG.md)
- [Commits](e460dfeb36...be8aa5be94)

---
updated-dependencies:
- dependency-name: dessant/lock-threads
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-12 19:03:17 +00:00
Nate Prewitt
8112fcc7be Pre commit update (#6498) 2023-08-12 12:03:10 -07:00
Nate Prewitt
2c193bda0c Pin GHA workflows and add dependabot to keep them up to date (#6497) 2023-08-12 12:02:58 -07:00
Ian Stapleton Cordasco
34a64bc65e Merge pull request #6266 from elprimato/spdx-conform-license
Change to SPDX conform license string
2023-08-12 13:51:42 -05:00
Nate Prewitt
9b6c62e235 Merge branch 'main' into spdx-conform-license 2023-08-12 11:37:15 -07:00
Joren Vrancken
cb7fcd7ebd Specify that Session.headers needs to be set to a OrderedDict in Header Ordering docs (#6475) 2023-08-12 10:53:36 -07:00
Calle Svensson
aa4cc78627 Add note about adapter prefix match to docs (#6465) 2023-07-29 21:05:44 -07:00
Kevin Kirsche
dfe46c1b7f refactor: prefer dictionary comphrension to loop (#6187) 2023-07-29 18:55:18 -07:00
Alexandre Erwin Ittner
2ecdb68561 Update reference to "cookielib" to "cookiejar" in documentation (#6214) 2023-07-29 18:50:43 -07:00
cpzt
fecf3dc472 add docstring parameter hooks (#6456) 2023-07-29 18:01:42 -07:00
Matthew Armand
cdbc2e2715 Add an Example for automatic retries to the Advanced Usage docs (#6258)
- While Requests doesn't automatically retry failures, this ability is a very common advanced use case in real world applications.
- Although there's a mention of this ability on the HTTPAdapter class docs, it's a bit buried and not very specific.
- It makes sense then to have an Example in the HTTPAdapter section of the Advanced Usage docs with a basic template for how this can be accomplished with Requests.
2023-07-03 13:38:22 -07:00
Boris Verkhovskiy
22db55a889 Fix doc typo (#6467) 2023-06-26 11:09:23 -06:00
Nate Prewitt
6e5b15d542 Fix linting issues 2023-05-22 09:36:22 -06:00
Volker Schaus
53a0562331 change to SPDX conform license string 2022-10-23 18:35:43 +00:00
78 changed files with 1279 additions and 218 deletions

View File

@@ -1,6 +1,9 @@
---
name: Request for Help
about: Guidance on using Requests.
labels:
- "Question/Not a bug"
- "actions/autoclose-qa"
---

View File

@@ -1,6 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
labels:
- "Feature Request"
- "actions/autoclose-feat"
---

11
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
ignore:
# Ignore all patch releases as we can manually
# upgrade if we run into a bug and need a fix.
- dependency-name: "*"
update-types: ["version-update:semver-patch"]

35
.github/workflows/close-issues.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: 'Autoclose Issues'
on:
issues:
types:
- labeled
permissions:
issues: write
jobs:
close_qa:
if: github.event.label.name == 'actions/autoclose-qa'
runs-on: ubuntu-latest
steps:
- env:
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
gh issue close $ISSUE_URL \
--comment "As described in the template, we won't be able to answer questions on this issue tracker. Please use [Stack Overflow](https://stackoverflow.com/)" \
--reason completed
gh issue lock $ISSUE_URL --reason off_topic
close_feature_request:
if: github.event.label.name == 'actions/autoclose-feat'
runs-on: ubuntu-latest
steps:
- env:
ISSUE_URL: ${{ github.event.issue.html_url }}
GH_TOKEN: ${{ github.token }}
run: |
gh issue close $ISSUE_URL \
--comment "As described in the template, Requests is not accepting feature requests" \
--reason "not planned"
gh issue lock $ISSUE_URL --reason off_topic

View File

@@ -32,7 +32,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
@@ -45,7 +45,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
languages: "python"
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -56,7 +56,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@@ -70,4 +70,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0

View File

@@ -11,10 +11,10 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: "3.x"
- name: Run pre-commit
uses: pre-commit/action@v3.0.0
uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0

View File

@@ -13,7 +13,7 @@ jobs:
if: github.repository_owner == 'psf'
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v3
- uses: dessant/lock-threads@d42e5f49803f3c4e14ffee0378e31481265dda22 # v5.0.0
with:
issue-lock-inactive-days: 90
pr-lock-inactive-days: 90

View File

@@ -12,23 +12,48 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8", "pypy-3.9"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.9", "pypy-3.10"]
os: [ubuntu-22.04, macOS-latest, windows-latest]
# Python 3.8 and 3.9 do not run on macOS-latest which
# is now using arm64 hardware.
# https://github.com/actions/setup-python/issues/696#issuecomment-1637587760
exclude:
- { python-version: "3.8", os: "macos-latest" }
- { python-version: "3.9", os: "macos-latest" }
include:
# pypy-3.7 on Windows and Mac OS currently fails trying to compile
# cryptography. Moving pypy-3.7 to only test linux.
- python-version: pypy-3.7
os: ubuntu-latest
- { python-version: "3.8", os: "macos-13" }
- { python-version: "3.9", os: "macos-13" }
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
make
- name: Run tests
run: |
make ci
no_chardet:
name: "No Character Detection"
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
- name: 'Set up Python 3.8'
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
with:
python-version: '3.8'
- name: Install dependencies
run: |
make
python -m pip uninstall -y "charset_normalizer" "chardet"
- name: Run tests
run: |
make ci

View File

@@ -2,7 +2,7 @@ exclude: 'docs/|ext/'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.4.0
hooks:
- id: check-yaml
- id: debug-statements
@@ -13,16 +13,16 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
exclude: tests/test_lowlevel.py
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8

29
.readthedocs.yaml Normal file
View File

@@ -0,0 +1,29 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
# Required
version: 2
# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
builder: "dirhtml"
# Optionally build your docs in additional formats such as PDF and ePub
formats:
- pdf
- epub
# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- path: .
- requirements: docs/requirements.txt

View File

@@ -8,7 +8,7 @@ Keepers of the Crystals
Previous Keepers of Crystals
````````````````````````````
- Kenneth Reitz <me@kennethreitz.org> `@ken-reitz <https://github.com/ken-reitz>`_, reluctant Keeper of the Master Crystal.
- Kenneth Reitz <me@kennethreitz.org> `@kennethreitz <https://github.com/kennethreitz>`_, reluctant Keeper of the Master Crystal.
- Cory Benfield <cory@lukasa.co.uk> `@lukasa <https://github.com/lukasa>`_
- Ian Cordasco <graffatcolmingov@gmail.com> `@sigmavirus24 <https://github.com/sigmavirus24>`_.
@@ -192,3 +192,4 @@ Patches and Suggestions
- Alessio Izzo (`@aless10 <https://github.com/aless10>`_)
- Sylvain Marié (`@smarie <https://github.com/smarie>`_)
- Hod Bin Noon (`@hodbn <https://github.com/hodbn>`_)
- Mike Fiedler (`@miketheman <https://github.com/miketheman>`_)

View File

@@ -6,6 +6,59 @@ dev
- \[Short description of non-trivial change.\]
2.32.1 (2024-05-20)
-------------------
**Bugfixes**
- Add missing test certs to the sdist distributed on PyPI.
2.32.0 (2024-05-20)
-------------------
**Security**
- Fixed an issue where setting `verify=False` on the first request from a
Session will cause subsequent requests to the _same origin_ to also ignore
cert verification, regardless of the value of `verify`.
(https://github.com/psf/requests/security/advisories/GHSA-9wx4-h78v-vm56)
**Improvements**
- `verify=True` now reuses a global SSLContext which should improve
request time variance between first and subsequent requests. It should
also minimize certificate load time on Windows systems when using a Python
version built with OpenSSL 3.x. (#6667)
- Requests now supports optional use of character detection
(`chardet` or `charset_normalizer`) when repackaged or vendored.
This enables `pip` and other projects to minimize their vendoring
surface area. The `Response.text()` and `apparent_encoding` APIs
will default to `utf-8` if neither library is present. (#6702)
**Bugfixes**
- Fixed bug in length detection where emoji length was incorrectly
calculated in the request content-length. (#6589)
- Fixed deserialization bug in JSONDecodeError. (#6629)
- Fixed bug where an extra leading `/` (path separator) could lead
urllib3 to unnecessarily reparse the request URI. (#6644)
**Deprecations**
- Requests has officially added support for CPython 3.12 (#6503)
- Requests has officially added support for PyPy 3.9 and 3.10 (#6641)
- Requests has officially dropped support for CPython 3.7 (#6642)
- Requests has officially dropped support for PyPy 3.7 and 3.8 (#6641)
**Documentation**
- Various typo fixes and doc improvements.
**Packaging**
- Requests has started adopting some modern packaging practices.
The source files for the projects (formerly `requests`) is now located
in `src/requests` in the Requests sdist. (#6506)
- Starting in Requests 2.33.0, Requests will migrate to a PEP 517 build system
using `hatchling`. This should not impact the average user, but extremely old
versions of packaging utilities may have issues with the new packaging format.
2.31.0 (2023-05-22)
-------------------
@@ -14,7 +67,7 @@ dev
forwarding of `Proxy-Authorization` headers to destination servers when
following HTTPS redirects.
When proxies are defined with user info (https://user:pass@proxy:8080), Requests
When proxies are defined with user info (`https://user:pass@proxy:8080`), Requests
will construct a `Proxy-Authorization` header that is attached to the request to
authenticate with the proxy.

View File

@@ -1,2 +1,3 @@
include README.md LICENSE NOTICE HISTORY.md pytest.ini requirements-dev.txt
include README.md LICENSE NOTICE HISTORY.md requirements-dev.txt
recursive-include tests *.py
recursive-include tests/certs *

View File

@@ -1,23 +1,23 @@
.PHONY: docs
init:
pip install -r requirements-dev.txt
python -m pip install -r requirements-dev.txt
test:
# This runs all of the tests on all supported Python versions.
tox -p
ci:
pytest tests --junitxml=report.xml
python -m pytest tests --junitxml=report.xml
test-readme:
python setup.py check --restructuredtext --strict && ([ $$? -eq 0 ] && echo "README.rst and HISTORY.rst ok") || echo "Invalid markup in README.rst or HISTORY.rst!"
flake8:
flake8 --ignore=E501,F401,E128,E402,E731,F821 requests
python -m flake8 src/requests
coverage:
pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=requests tests
python -m pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=src/requests tests
publish:
pip install 'twine>=1.5.0'
python -m pip install 'twine>=1.5.0'
python setup.py sdist bdist_wheel
twine upload dist/*
rm -fr build dist .egg requests.egg-info

View File

@@ -21,7 +21,7 @@ Requests allows you to send HTTP/1.1 requests extremely easily. Theres no nee
Requests is one of the most downloaded Python packages today, pulling in around `30M downloads / week`— according to GitHub, Requests is currently [depended upon](https://github.com/psf/requests/network/dependents?package_id=UGFja2FnZS01NzA4OTExNg%3D%3D) by `1,000,000+` repositories. You may certainly put your trust in this code.
[![Downloads](https://pepy.tech/badge/requests/month)](https://pepy.tech/project/requests)
[![Downloads](https://static.pepy.tech/badge/requests/month)](https://pepy.tech/project/requests)
[![Supported Versions](https://img.shields.io/pypi/pyversions/requests.svg)](https://pypi.org/project/requests)
[![Contributors](https://img.shields.io/github/contributors/psf/requests.svg)](https://github.com/psf/requests/graphs/contributors)
@@ -33,7 +33,7 @@ Requests is available on PyPI:
$ python -m pip install requests
```
Requests officially supports Python 3.7+.
Requests officially supports Python 3.8+.
## Supported Features & BestPractices

View File

@@ -16,15 +16,15 @@
<h3>Useful Links</h3>
<ul>
<li><a href="https://requests.readthedocs.io/en/latest/user/quickstart/">Quickstart</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/user/advanced/">Advanced Usage</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/api/">API Reference</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/community/updates/#release-history">Release History</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/dev/contributing/">Contributors Guide</a></li>
<li><a href="{{ pathto('user/quickstart') }}">Quickstart</a></li>
<li><a href="{{ pathto('user/advanced') }}">Advanced Usage</a></li>
<li><a href="{{ pathto('api') }}">API Reference</a></li>
<li><a href="{{ pathto('community/updates') + '#release-history' }}">Release History</a></li>
<li><a href="{{ pathto('dev/contributing') }}">Contributors Guide</a></li>
<p></p>
<li><a href="https://requests.readthedocs.io/en/latest/community/recommended/">Recommended Packages and Extensions</a></li>
<li><a href="{{ pathto('community/recommended') }}">Recommended Packages and Extensions</a></li>
<p></p>

View File

@@ -11,15 +11,15 @@
<h3>Useful Links</h3>
<ul>
<li><a href="https://requests.readthedocs.io/en/latest/user/quickstart/">Quickstart</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/user/advanced/">Advanced Usage</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/api/">API Reference</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/community/updates/#release-history">Release History</a></li>
<li><a href="https://requests.readthedocs.io/en/latest/dev/contributing/">Contributors Guide</a></li>
<li><a href="{{ pathto('user/quickstart') }}">Quickstart</a></li>
<li><a href="{{ pathto('user/advanced') }}">Advanced Usage</a></li>
<li><a href="{{ pathto('api') }}">API Reference</a></li>
<li><a href="{{ pathto('community/updates') + '#release-history' }}">Release History</a></li>
<li><a href="{{ pathto('dev/contributing') }}">Contributors Guide</a></li>
<p></p>
<li><a href="https://requests.readthedocs.io/en/latest/community/recommended/">Recommended Packages and Extensions</a></li>
<li><a href="{{ pathto('community/recommended') }}">Recommended Packages and Extensions</a></li>
<p></p>

View File

@@ -22,7 +22,7 @@ Custom User-Agents?
-------------------
Requests allows you to easily override User-Agent strings, along with
any other HTTP Header. See `documentation about headers <https://requests.readthedocs.io/en/latest/user/quickstart/#custom-headers>`_.
any other HTTP Header. See :ref:`documentation about headers <custom-headers>`.
@@ -55,7 +55,7 @@ Chris Adams gave an excellent summary on
Python 3 Support?
-----------------
Yes! Requests officially supports Python 3.7+ and PyPy.
Yes! Requests officially supports Python 3.8+ and PyPy.
Python 2 Support?
-----------------

View File

@@ -1,22 +1,10 @@
Integrations
============
Python for iOS
--------------
Requests is built into the wonderful `Python for iOS <https://itunes.apple.com/us/app/python-2.7-for-ios/id485729872?mt=Python8>`_ runtime!
To give it a try, simply::
import requests
Articles & Talks
================
- `Python for the Web <https://www.gun.io/blog/python-for-the-web>`_ teaches how to use Python to interact with the web, using Requests.
- `Daniel Greenfeld's Review of Requests <https://pydanny.blogspot.com/2011/05/python-http-requests-for-humans.html>`_
- `My 'Python for Humans' talk <http://python-for-humans.heroku.com>`_ ( `audio <https://codeconf.s3.amazonaws.com/2011/pycodeconf/talks/PyCodeConf2011%20-%20Kenneth%20Reitz.m4a>`_ )
- `Issac Kelly's 'Consuming Web APIs' talk <https://issackelly.github.com/Consuming-Web-APIs-with-Python-Talk/slides/slides.html>`_
- `Issac Kelly's 'Consuming Web APIs' talk <https://issackelly.github.io/Consuming-Web-APIs-with-Python-Talk/slides/slides.html>`_
- `Blog post about Requests via Yum <https://arunsag.wordpress.com/2011/08/17/new-package-python-requests-http-for-humans/>`_
- `Russian blog post introducing Requests <https://habr.com/post/126262/>`_
- `Sending JSON in Requests <http://www.coglib.com/~icordasc/blog/2014/11/sending-json-in-requests.html>`_

View File

@@ -9,7 +9,7 @@ Requests: HTTP for Humans™
Release v\ |version|. (:ref:`Installation <install>`)
.. image:: https://pepy.tech/badge/requests/month
.. image:: https://static.pepy.tech/badge/requests/month
:target: https://pepy.tech/project/requests
:alt: Requests Downloads Per Month Badge
@@ -72,7 +72,7 @@ Requests is ready for today's web.
- Chunked Requests
- ``.netrc`` Support
Requests officially supports Python 3.7+, and runs great on PyPy.
Requests officially supports Python 3.8+, and runs great on PyPy.
The User Guide

View File

@@ -1,3 +1,3 @@
# Pinning to avoid unexpected breakages.
# Used by RTD to generate docs.
Sphinx==4.2.0
Sphinx==7.2.6

View File

@@ -291,7 +291,7 @@ versions of Requests.
For the sake of security we recommend upgrading certifi frequently!
.. _HTTP persistent connection: https://en.wikipedia.org/wiki/HTTP_persistent_connection
.. _connection pooling: https://urllib3.readthedocs.io/en/latest/reference/index.html#module-urllib3.connectionpool
.. _connection pooling: https://urllib3.readthedocs.io/en/latest/reference/urllib3.connectionpool.html
.. _certifi: https://certifiio.readthedocs.io/
.. _Mozilla trust store: https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt
@@ -666,6 +666,8 @@ You override this default certificate bundle by setting the ``REQUESTS_CA_BUNDLE
>>> import requests
>>> requests.get('https://example.org')
.. _socks:
SOCKS
^^^^^
@@ -946,7 +948,7 @@ Link Headers
Many HTTP APIs feature Link headers. They make APIs more self describing and
discoverable.
GitHub uses these for `pagination <https://developer.github.com/v3/#pagination>`_
GitHub uses these for `pagination <https://docs.github.com/en/rest/guides/using-pagination-in-the-rest-api>`_
in their API, for example::
>>> url = 'https://api.github.com/users/kennethreitz/repos?page=1&per_page=10'
@@ -994,6 +996,10 @@ The mount call registers a specific instance of a Transport Adapter to a
prefix. Once mounted, any HTTP request made using that session whose URL starts
with the given prefix will use the given Transport Adapter.
.. note:: The adapter will be chosen based on a longest prefix match. Be mindful
prefixes such as ``http://localhost`` will also match ``http://localhost.other.com``
or ``http://localhost@other.com``. It's recommended to terminate full hostnames with a ``/``.
Many of the details of implementing a Transport Adapter are beyond the scope of
this documentation, but take a look at the next example for a simple SSL use-
case. For more than that, you might look at subclassing the
@@ -1026,8 +1032,30 @@ library to use SSLv3::
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_SSLv3)
Example: Automatic Retries
^^^^^^^^^^^^^^^^^^^^^^^^^^
By default, Requests does not retry failed connections. However, it is possible
to implement automatic retries with a powerful array of features, including
backoff, within a Requests :class:`Session <requests.Session>` using the
`urllib3.util.Retry`_ class::
from urllib3.util import Retry
from requests import Session
from requests.adapters import HTTPAdapter
s = Session()
retries = Retry(
total=3,
backoff_factor=0.1,
status_forcelist=[502, 503, 504],
allowed_methods={'POST'},
)
s.mount('https://', HTTPAdapter(max_retries=retries))
.. _`described here`: https://kenreitz.org/essays/2012/06/14/the-future-of-python-http
.. _`urllib3`: https://github.com/urllib3/urllib3
.. _`urllib3.util.Retry`: https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Retry
.. _blocking-or-nonblocking:
@@ -1055,7 +1083,7 @@ Header Ordering
In unusual circumstances you may want to provide headers in an ordered manner. If you pass an ``OrderedDict`` to the ``headers`` keyword argument, that will provide the headers with an ordering. *However*, the ordering of the default headers used by Requests will be preferred, which means that if you override default headers in the ``headers`` keyword argument, they may appear out of order compared to other headers in that keyword argument.
If this is problematic, users should consider setting the default headers on a :class:`Session <requests.Session>` object, by setting :attr:`Session <requests.Session.headers>` to a custom ``OrderedDict``. That ordering will always be preferred.
If this is problematic, users should consider setting the default headers on a :class:`Session <requests.Session>` object, by setting :attr:`Session.headers <requests.Session.headers>` to a custom ``OrderedDict``. That ordering will always be preferred.
.. _timeouts:
@@ -1071,7 +1099,7 @@ The **connect** timeout is the number of seconds Requests will wait for your
client to establish a connection to a remote machine (corresponding to the
`connect()`_) call on the socket. It's a good practice to set connect timeouts
to slightly larger than a multiple of 3, which is the default `TCP packet
retransmission window <https://www.hjp.at/doc/rfc/rfc2988.txt>`_.
retransmission window <https://datatracker.ietf.org/doc/html/rfc2988>`_.
Once your client has connected to the server and sent the HTTP request, the
**read** timeout is the number of seconds the client will wait for the server
@@ -1096,4 +1124,18 @@ coffee.
r = requests.get('https://github.com', timeout=None)
.. note:: The connect timeout applies to each connection attempt to an IP address.
If multiple addresses exist for a domain name, the underlying ``urllib3`` will
try each address sequentially until one successfully connects.
This may lead to an effective total connection timeout *multiple* times longer
than the specified time, e.g. an unresponsive server having both IPv4 and IPv6
addresses will have its perceived timeout *doubled*, so take that into account
when setting the connection timeout.
.. note:: Neither the connect nor read timeouts are `wall clock`_. This means
that if you start a request, and look at the time, and then look at
the time when the request finishes or times out, the real-world time
may be greater than what you specified.
.. _`wall clock`: https://wiki.php.net/rfc/max_execution_wall_time
.. _`connect()`: https://linux.die.net/man/2/connect

View File

@@ -201,6 +201,8 @@ may better fit your use cases.
were returned, use ``Response.raw``.
.. _custom-headers:
Custom Headers
--------------
@@ -566,6 +568,3 @@ All exceptions that Requests explicitly raises inherit from
-----------------------
Ready for more? Check out the :ref:`advanced <advanced>` section.
If you're on the job market, consider taking `this programming quiz <https://triplebyte.com/a/b1i2FB8/requests-docs-1>`_. A substantial donation will be made to this project, if you find a job through this platform.

View File

@@ -1,13 +1,10 @@
[tool.isort]
profile = "black"
src_paths = ["requests", "test"]
src_paths = ["src/requests", "test"]
honor_noqa = true
[tool.pytest.ini_options]
addopts = "--doctest-modules"
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
minversion = "6.2"
testpaths = [
"requests",
"tests",
]
testpaths = ["tests"]

View File

@@ -1,13 +1,7 @@
-e .[socks]
pytest>=2.8.0,<=6.2.5
pytest>=2.8.0,<9
pytest-cov
pytest-httpbin==2.0.0
pytest-mock==2.0.0
httpbin==0.7.0
httpbin~=0.10.0
trustme
wheel
cryptography<40.0.0; python_version <= '3.7' and platform_python_implementation == 'PyPy'
# Flask Stack
Flask>1.0,<2.0
markupsafe<2.1

View File

@@ -7,11 +7,11 @@ requires-dist =
certifi>=2017.4.17
charset_normalizer>=2,<4
idna>=2.5,<4
urllib3>=1.21.1,<1.27
urllib3>=1.21.1,<3
[flake8]
ignore = E203, E501, W503
per-file-ignores =
requests/__init__.py:E402, F401
requests/compat.py:E402, F401
src/requests/__init__.py:E402, F401
src/requests/compat.py:E402, F401
tests/compat.py:F401

View File

@@ -7,7 +7,7 @@ from setuptools import setup
from setuptools.command.test import test as TestCommand
CURRENT_PYTHON = sys.version_info[:2]
REQUIRED_PYTHON = (3, 7)
REQUIRED_PYTHON = (3, 8)
if CURRENT_PYTHON < REQUIRED_PYTHON:
sys.stderr.write(
@@ -20,7 +20,7 @@ you're trying to install it on Python {}.{}. To resolve this,
consider upgrading to a supported Python version.
If you can't upgrade your Python version, you'll need to
pin to an older version of Requests (<2.28).
pin to an older version of Requests (<2.32.0).
""".format(
*(REQUIRED_PYTHON + CURRENT_PYTHON)
)
@@ -75,7 +75,7 @@ test_requirements = [
about = {}
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "requests", "__version__.py"), "r", "utf-8") as f:
with open(os.path.join(here, "src", "requests", "__version__.py"), "r", "utf-8") as f:
exec(f.read(), about)
with open("README.md", "r", "utf-8") as f:
@@ -92,9 +92,9 @@ setup(
url=about["__url__"],
packages=["requests"],
package_data={"": ["LICENSE", "NOTICE"]},
package_dir={"requests": "requests"},
package_dir={"": "src"},
include_package_data=True,
python_requires=">=3.7",
python_requires=">=3.8",
install_requires=requires,
license=about["__license__"],
zip_safe=False,
@@ -107,11 +107,11 @@ setup(
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",

View File

@@ -83,7 +83,11 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
# charset_normalizer >= 2.0.0 < 4.0.0
assert (2, 0, 0) <= (major, minor, patch) < (4, 0, 0)
else:
raise Exception("You need either charset_normalizer or chardet installed")
warnings.warn(
"Unable to find acceptable character detection dependency "
"(chardet or charset_normalizer).",
RequestsDependencyWarning,
)
def _check_cryptography(cryptography_version):

View File

@@ -5,10 +5,10 @@
__title__ = "requests"
__description__ = "Python HTTP for Humans."
__url__ = "https://requests.readthedocs.io"
__version__ = "2.31.0"
__build__ = 0x023100
__version__ = "2.32.1"
__build__ = 0x023201
__author__ = "Kenneth Reitz"
__author_email__ = "me@kennethreitz.org"
__license__ = "Apache 2.0"
__license__ = "Apache-2.0"
__copyright__ = "Copyright Kenneth Reitz"
__cake__ = "\u2728 \U0001f370 \u2728"

View File

@@ -8,6 +8,7 @@ and maintain connections.
import os.path
import socket # noqa: F401
import typing
from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
from urllib3.exceptions import HTTPError as _HTTPError
@@ -25,6 +26,7 @@ from urllib3.poolmanager import PoolManager, proxy_from_url
from urllib3.util import Timeout as TimeoutSauce
from urllib3.util import parse_url
from urllib3.util.retry import Retry
from urllib3.util.ssl_ import create_urllib3_context
from .auth import _basic_auth_str
from .compat import basestring, urlparse
@@ -61,11 +63,57 @@ except ImportError:
raise InvalidSchema("Missing dependencies for SOCKS support.")
if typing.TYPE_CHECKING:
from .models import PreparedRequest
DEFAULT_POOLBLOCK = False
DEFAULT_POOLSIZE = 10
DEFAULT_RETRIES = 0
DEFAULT_POOL_TIMEOUT = None
_preloaded_ssl_context = create_urllib3_context()
_preloaded_ssl_context.load_verify_locations(
extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
)
def _urllib3_request_context(
request: "PreparedRequest",
verify: "bool | str | None",
client_cert: "typing.Tuple[str, str] | str | None",
) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
host_params = {}
pool_kwargs = {}
parsed_request_url = urlparse(request.url)
scheme = parsed_request_url.scheme.lower()
port = parsed_request_url.port
cert_reqs = "CERT_REQUIRED"
if verify is False:
cert_reqs = "CERT_NONE"
elif verify is True:
pool_kwargs["ssl_context"] = _preloaded_ssl_context
elif isinstance(verify, str):
if not os.path.isdir(verify):
pool_kwargs["ca_certs"] = verify
else:
pool_kwargs["ca_cert_dir"] = verify
pool_kwargs["cert_reqs"] = cert_reqs
if client_cert is not None:
if isinstance(client_cert, tuple) and len(client_cert) == 2:
pool_kwargs["cert_file"] = client_cert[0]
pool_kwargs["key_file"] = client_cert[1]
else:
# According to our docs, we allow users to specify just the client
# cert path
pool_kwargs["cert_file"] = client_cert
host_params = {
"scheme": scheme,
"host": parsed_request_url.hostname,
"port": port,
}
return host_params, pool_kwargs
class BaseAdapter:
"""The Base Transport Adapter"""
@@ -247,28 +295,26 @@ class HTTPAdapter(BaseAdapter):
:param cert: The SSL certificate to verify.
"""
if url.lower().startswith("https") and verify:
cert_loc = None
# Allow self-specified cert location.
if verify is not True:
cert_loc = verify
if not cert_loc:
cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
if not cert_loc or not os.path.exists(cert_loc):
raise OSError(
f"Could not find a suitable TLS CA certificate bundle, "
f"invalid path: {cert_loc}"
)
conn.cert_reqs = "CERT_REQUIRED"
if not os.path.isdir(cert_loc):
conn.ca_certs = cert_loc
else:
conn.ca_cert_dir = cert_loc
# Only load the CA certificates if 'verify' is a string indicating the CA bundle to use.
# Otherwise, if verify is a boolean, we don't load anything since
# the connection will be using a context with the default certificates already loaded,
# and this avoids a call to the slow load_verify_locations()
if verify is not True:
# `verify` must be a str with a path then
cert_loc = verify
if not os.path.exists(cert_loc):
raise OSError(
f"Could not find a suitable TLS CA certificate bundle, "
f"invalid path: {cert_loc}"
)
if not os.path.isdir(cert_loc):
conn.ca_certs = cert_loc
else:
conn.ca_cert_dir = cert_loc
else:
conn.cert_reqs = "CERT_NONE"
conn.ca_certs = None
@@ -328,6 +374,35 @@ class HTTPAdapter(BaseAdapter):
return response
def _get_connection(self, request, verify, proxies=None, cert=None):
# Replace the existing get_connection without breaking things and
# ensure that TLS settings are considered when we interact with
# urllib3 HTTP Pools
proxy = select_proxy(request.url, proxies)
try:
host_params, pool_kwargs = _urllib3_request_context(request, verify, cert)
except ValueError as e:
raise InvalidURL(e, request=request)
if proxy:
proxy = prepend_scheme_if_needed(proxy, "http")
proxy_url = parse_url(proxy)
if not proxy_url.host:
raise InvalidProxyURL(
"Please check proxy URL. It is malformed "
"and could be missing the host."
)
proxy_manager = self.proxy_manager_for(proxy)
conn = proxy_manager.connection_from_host(
**host_params, pool_kwargs=pool_kwargs
)
else:
# Only scheme should be lower case
conn = self.poolmanager.connection_from_host(
**host_params, pool_kwargs=pool_kwargs
)
return conn
def get_connection(self, url, proxies=None):
"""Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
@@ -391,6 +466,9 @@ class HTTPAdapter(BaseAdapter):
using_socks_proxy = proxy_scheme.startswith("socks")
url = request.path_url
if url.startswith("//"): # Don't confuse urllib3
url = f"/{url.lstrip('/')}"
if is_proxied_http_request and not using_socks_proxy:
url = urldefragauth(request.url)
@@ -451,7 +529,7 @@ class HTTPAdapter(BaseAdapter):
"""
try:
conn = self.get_connection(request.url, proxies)
conn = self._get_connection(request, verify, proxies=proxies, cert=cert)
except LocationValueError as e:
raise InvalidURL(e, request=request)

View File

@@ -25,7 +25,7 @@ def request(method, url, **kwargs):
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content_type'`` is a string
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
to add for the file.
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.

View File

@@ -258,7 +258,6 @@ class HTTPDigestAuth(AuthBase):
s_auth = r.headers.get("www-authenticate", "")
if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2:
self._thread_local.num_401_calls += 1
pat = re.compile(r"digest ", flags=re.IGNORECASE)
self._thread_local.chal = parse_dict_header(pat.sub("", s_auth, count=1))

View File

@@ -7,13 +7,28 @@ between Python 2 and Python 3. It remains for backwards
compatibility until the next major version.
"""
try:
import chardet
except ImportError:
import charset_normalizer as chardet
import importlib
import sys
# -------------------
# Character Detection
# -------------------
def _resolve_char_detection():
"""Find supported character detection libraries."""
chardet = None
for lib in ("chardet", "charset_normalizer"):
if chardet is None:
try:
chardet = importlib.import_module(lib)
except ImportError:
pass
return chardet
chardet = _resolve_char_detection()
# -------
# Pythons
# -------

View File

@@ -2,7 +2,7 @@
requests.cookies
~~~~~~~~~~~~~~~~
Compatibility code to be able to use `cookielib.CookieJar` with requests.
Compatibility code to be able to use `http.cookiejar.CookieJar` with requests.
requests.utils imports from here, so be careful with imports.
"""
@@ -23,7 +23,7 @@ except ImportError:
class MockRequest:
"""Wraps a `requests.Request` to mimic a `urllib2.Request`.
The code in `cookielib.CookieJar` expects this interface in order to correctly
The code in `http.cookiejar.CookieJar` expects this interface in order to correctly
manage cookie policies, i.e., determine whether a cookie can be set, given the
domains of the request and the cookie.
@@ -76,7 +76,7 @@ class MockRequest:
return self._r.headers.get(name, self._new_headers.get(name, default))
def add_header(self, key, val):
"""cookielib has no legitimate use for this method; add it back if you find one."""
"""cookiejar has no legitimate use for this method; add it back if you find one."""
raise NotImplementedError(
"Cookie headers should be added with add_unredirected_header()"
)
@@ -104,11 +104,11 @@ class MockResponse:
"""Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
...what? Basically, expose the parsed HTTP headers from the server response
the way `cookielib` expects to see them.
the way `http.cookiejar` expects to see them.
"""
def __init__(self, headers):
"""Make a MockResponse for `cookielib` to read.
"""Make a MockResponse for `cookiejar` to read.
:param headers: a httplib.HTTPMessage or analogous carrying the headers
"""
@@ -124,7 +124,7 @@ class MockResponse:
def extract_cookies_to_jar(jar, request, response):
"""Extract the cookies from the response into a CookieJar.
:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
:param jar: http.cookiejar.CookieJar (not necessarily a RequestsCookieJar)
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object
"""
@@ -174,7 +174,7 @@ class CookieConflictError(RuntimeError):
class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
"""Compatibility class; is a cookielib.CookieJar, but exposes a dict
"""Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict
interface.
This is the CookieJar we create by default for requests and sessions that
@@ -341,7 +341,7 @@ class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
self.set(name, value)
def __delitem__(self, name):
"""Deletes a cookie given a name. Wraps ``cookielib.CookieJar``'s
"""Deletes a cookie given a name. Wraps ``http.cookiejar.CookieJar``'s
``remove_cookie_by_name()``.
"""
remove_cookie_by_name(self, name)

View File

@@ -41,6 +41,16 @@ class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
CompatJSONDecodeError.__init__(self, *args)
InvalidJSONError.__init__(self, *self.args, **kwargs)
def __reduce__(self):
"""
The __reduce__ method called when pickling the object must
be the one from the JSONDecodeError (be it json/simplejson)
as it expects all the arguments for instantiation, not just
one like the IOError, and the MRO would by default call the
__reduce__ method from the IOError due to the inheritance order.
"""
return CompatJSONDecodeError.__reduce__(self)
class HTTPError(RequestException):
"""An HTTP error occurred."""

View File

@@ -170,7 +170,7 @@ class RequestEncodingMixin:
)
)
for (k, v) in files:
for k, v in files:
# support for explicit filename
ft = None
fh = None
@@ -268,7 +268,6 @@ class Request(RequestHooksMixin):
hooks=None,
json=None,
):
# Default empty dicts for dict params.
data = [] if data is None else data
files = [] if files is None else files
@@ -277,7 +276,7 @@ class Request(RequestHooksMixin):
hooks = {} if hooks is None else hooks
self.hooks = default_hooks()
for (k, v) in list(hooks.items()):
for k, v in list(hooks.items()):
self.register_hook(event=k, hook=v)
self.method = method
@@ -790,7 +789,12 @@ class Response:
@property
def apparent_encoding(self):
"""The apparent encoding, provided by the charset_normalizer or chardet libraries."""
return chardet.detect(self.content)["encoding"]
if chardet is not None:
return chardet.detect(self.content)["encoding"]
else:
# If no character detection library is available, we'll fall back
# to a standard Python utf-8 str.
return "utf-8"
def iter_content(self, chunk_size=1, decode_unicode=False):
"""Iterates over the response data. When stream=True is set on the
@@ -865,7 +869,6 @@ class Response:
for chunk in self.iter_content(
chunk_size=chunk_size, decode_unicode=decode_unicode
):
if pending is not None:
chunk = pending + chunk

View File

@@ -1,13 +1,6 @@
import sys
try:
import chardet
except ImportError:
import warnings
import charset_normalizer as chardet
warnings.filterwarnings("ignore", "Trying to detect", module="charset_normalizer")
from .compat import chardet
# This code exists for backwards compatibility reasons.
# I don't like it either. Just look the other way. :)
@@ -20,9 +13,11 @@ for package in ("urllib3", "idna"):
if mod == package or mod.startswith(f"{package}."):
sys.modules[f"requests.packages.{mod}"] = sys.modules[mod]
target = chardet.__name__
for mod in list(sys.modules):
if mod == target or mod.startswith(f"{target}."):
target = target.replace(target, "chardet")
sys.modules[f"requests.packages.{target}"] = sys.modules[mod]
# Kinda cool, though, right?
if chardet is not None:
target = chardet.__name__
for mod in list(sys.modules):
if mod == target or mod.startswith(f"{target}."):
imported_mod = sys.modules[mod]
sys.modules[f"requests.packages.{mod}"] = imported_mod
mod = mod.replace(target, "chardet")
sys.modules[f"requests.packages.{mod}"] = imported_mod

View File

@@ -262,7 +262,6 @@ class SessionRedirectMixin:
if yield_requests:
yield req
else:
resp = self.send(
req,
stream=stream,
@@ -326,7 +325,7 @@ class SessionRedirectMixin:
# urllib3 handles proxy authorization for us in the standard adapter.
# Avoid appending this to TLS tunneled requests where it may be leaked.
if not scheme.startswith('https') and username and password:
if not scheme.startswith("https") and username and password:
headers["Proxy-Authorization"] = _basic_auth_str(username, password)
return new_proxies
@@ -389,7 +388,6 @@ class Session(SessionRedirectMixin):
]
def __init__(self):
#: A case-insensitive dictionary of headers to be sent on each
#: :class:`Request <Request>` sent from this
#: :class:`Session <Session>`.
@@ -545,6 +543,8 @@ class Session(SessionRedirectMixin):
:type allow_redirects: bool
:param proxies: (optional) Dictionary mapping protocol or protocol and
hostname to the URL of the proxy.
:param hooks: (optional) Dictionary mapping hook name to one event or
list of events, event must be callable.
:param stream: (optional) whether to immediately download the response
content. Defaults to ``False``.
:param verify: (optional) Either a boolean, in which case it controls whether we verify
@@ -711,7 +711,6 @@ class Session(SessionRedirectMixin):
# Persist cookies
if r.history:
# If the hooks create history then we want those cookies too
for resp in r.history:
extract_cookies_to_jar(self.cookies, resp.request, resp.raw)
@@ -759,7 +758,7 @@ class Session(SessionRedirectMixin):
# Set environment's proxies.
no_proxy = proxies.get("no_proxy") if proxies is not None else None
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
for (k, v) in env_proxies.items():
for k, v in env_proxies.items():
proxies.setdefault(k, v)
# Look for requests environment configuration
@@ -785,8 +784,7 @@ class Session(SessionRedirectMixin):
:rtype: requests.adapters.BaseAdapter
"""
for (prefix, adapter) in self.adapters.items():
for prefix, adapter in self.adapters.items():
if url.lower().startswith(prefix.lower()):
return adapter

View File

@@ -24,7 +24,7 @@ _codes = {
# Informational.
100: ("continue",),
101: ("switching_protocols",),
102: ("processing",),
102: ("processing", "early-hints"),
103: ("checkpoint",),
122: ("uri_too_long", "request_uri_too_long"),
200: ("ok", "okay", "all_ok", "all_okay", "all_good", "\\o/", ""),
@@ -65,8 +65,8 @@ _codes = {
410: ("gone",),
411: ("length_required",),
412: ("precondition_failed", "precondition"),
413: ("request_entity_too_large",),
414: ("request_uri_too_large",),
413: ("request_entity_too_large", "content_too_large"),
414: ("request_uri_too_large", "uri_too_long"),
415: ("unsupported_media_type", "unsupported_media", "media_type"),
416: (
"requested_range_not_satisfiable",
@@ -76,10 +76,10 @@ _codes = {
417: ("expectation_failed",),
418: ("im_a_teapot", "teapot", "i_am_a_teapot"),
421: ("misdirected_request",),
422: ("unprocessable_entity", "unprocessable"),
422: ("unprocessable_entity", "unprocessable", "unprocessable_content"),
423: ("locked",),
424: ("failed_dependency", "dependency"),
425: ("unordered_collection", "unordered"),
425: ("unordered_collection", "unordered", "too_early"),
426: ("upgrade_required", "upgrade"),
428: ("precondition_required", "precondition"),
429: ("too_many_requests", "too_many"),

View File

@@ -97,6 +97,8 @@ if sys.platform == "win32":
# '<local>' string by the localhost entry and the corresponding
# canonical entry.
proxyOverride = proxyOverride.split(";")
# filter out empty strings to avoid re.match return true in the following code.
proxyOverride = filter(None, proxyOverride)
# now check if we match one of the registry values.
for test in proxyOverride:
if test == "<local>":
@@ -134,6 +136,9 @@ def super_len(o):
total_length = None
current_position = 0
if isinstance(o, str):
o = o.encode("utf-8")
if hasattr(o, "__len__"):
total_length = len(o)
@@ -466,11 +471,7 @@ def dict_from_cookiejar(cj):
:rtype: dict
"""
cookie_dict = {}
for cookie in cj:
cookie_dict[cookie.name] = cookie.value
cookie_dict = {cookie.name: cookie.value for cookie in cj}
return cookie_dict
@@ -767,6 +768,7 @@ def should_bypass_proxies(url, no_proxy):
:rtype: bool
"""
# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
def get_proxy(key):
@@ -862,7 +864,7 @@ def select_proxy(url, proxies):
def resolve_proxies(request, proxies, trust_env=True):
"""This method takes proxy information from a request and configuration
input to resolve a mapping of target proxies. This will consider settings
such a NO_PROXY to strip proxy configurations.
such as NO_PROXY to strip proxy configurations.
:param request: Request or PreparedRequest
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
@@ -1054,7 +1056,7 @@ def _validate_header_part(header, header_part, header_validator_index):
if not validator.match(header_part):
header_kind = "name" if header_validator_index == 0 else "value"
raise InvalidHeader(
f"Invalid leading whitespace, reserved character(s), or return"
f"Invalid leading whitespace, reserved character(s), or return "
f"character(s) in header {header_kind}: {header_part!r}"
)

10
tests/certs/README.md Normal file
View File

@@ -0,0 +1,10 @@
# Testing Certificates
This is a collection of certificates useful for testing aspects of Requests'
behaviour.
The certificates include:
* [expired](./expired) server certificate with a valid certificate authority
* [mtls](./mtls) provides a valid client certificate with a 2 year validity
* [valid](./valid) has a valid server certificate

View File

@@ -0,0 +1,13 @@
.PHONY: all clean ca server
ca:
make -C $@ all
server:
make -C $@ all
all: ca server
clean:
make -C ca clean
make -C server clean

View File

@@ -0,0 +1,11 @@
# Expired Certificates and Configuration for Testing
This has a valid certificate authority in [ca](./ca) and an invalid server
certificate in [server](./server).
This can all be regenerated with:
```
make clean
make all
```

View File

@@ -0,0 +1,13 @@
.PHONY: all clean
root_files = ca-private.key ca.crt
ca-private.key:
openssl genrsa -out ca-private.key 2048
all: ca-private.key
openssl req -x509 -sha256 -days 7300 -key ca-private.key -out ca.crt -config ca.cnf
ln -s ca.crt cacert.pem
clean:
rm -f cacert.pem ca.crt ca-private.key *.csr

View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHlIhe7GLCeSk8
RZOKdtmyKns6KdZgGw/LcxPkYvQlu1g0zV8X0DqVr2LdMumWUTNCc9sPdSlAG+He
mQp2TMoWUMumMuwDtit9RT0Sb6Eh9svWgjY9ferovPJRfCWUTsA2Ug8uoh0wyEXK
na7X6fHt5E3B9vj0+b9a4vDibdBXV11FheLT02/uEmAEJDdP/zeBgvVbhcVyumO6
fAGMIWzR2ukhe8z/ma5H9zoi4gZA8nsK6reZUD8+6affnPe+jIt/AdzggtV9jkWm
zSpr+RHeZ0y+q4eik2ZNUGg4XcF6JsJ9yu/AqLBXxd38uLdFfgyhP2y6K628yzgy
e6lzFyWnAgMBAAECggEAFwzHhzcD3PQDWCus85PwZoxTeQ817BmUBGpBBOKM0gLG
GCsT7XsmGP2NjICBy9OK+QTKawmb/wR5XK0OMUWDHXqtWn+NFIyojyo8+HEeCf8n
4ZleTFHLnJ+d2N1etbc2qc9mY3tjpaurq8/0Tol9YH06ock1TY2+lO+a5HvMURnY
hcWs70CamL+5B/6n67DhjzMtIW3dIXuEEceM1BW/jW8SKq0JHpQ3t+OJwID7zFaJ
bLyOwAVheMzVGvN3yphf8tll3tMA65bNjdOzgOfZSjAy7EGjW3DyAolDw9jKLRyu
E0gw/exNGe618oMIeUDv0KParlL4RjdiUP8l0xYOwQKBgQD3eYj9rWeqZquI9vKP
gaSv6urb2UJLngShZUpEZRNJgBO+Ewiof0w8tpQdsnuMvWudxMLbzgiUNA+NyC/K
CpzIXFkWnWx+A/pxs8ZO8moOfajVRayJgeOLsQZb7c4fXGsVGApbN4+cPNhTNG6d
ucErv6tae/SzAzcLc5Vkw/ELxwKBgQDOdJ5Wl5JeKAvU/3kF6+MYWCrXxZqMjoHS
y1BtyMX5RbdaWTCfDUu1aV3qJOJjjWQ9DJdJQcEsrTjOpD4bVdZx4w/XEG0JXAa3
jRypVHGdeG/TjhUGJA8U+KX3a1DkcdqM9pqFYRw5Ie95Wz9YRroI+YkixqpK8d7W
C+5BodxXIQKBgCk8Lv9V7XgPM3XW8APJbk+BrTCEuu8unUbnQcCztssAdEmvkjnB
PErBgVyRaNTCmzPmnTFS20sWgaD2QkBAFG+uM4n5ISK+NvTLJ7fv3IwdlAw1V9Jx
uiCElrKqpTXEiHMzVkZss5ks6j6y9duCIBXSEhM5pERPvNRDphjsLTXxAoGARSNC
nyb1Kjjo9XR0V+pNy6pC9q1C+00B5tCVZ55zxe114Hi70pfGQcM+YxnlAoeoCNW9
mBfAFDESNAlGjyrovIzYkiH7EcZSrYdBEOepgJ2DfWo4Wi0bK9+03K2AknAaS1iO
GJqTtAJMSuymwu40gKroJNA42Q40nKO0LyCARGECgYEAiFRHkblBtStv22SpZxNC
jim9yuM0ikh7Ij1lEHysc/GWb2RQNxQVk54BU2kQ0d9xwMZQTKvpF3VE9t7uGdwt
AasWPr/tWYt35Ud0D4bNlagJJ4Xdslf8n1nkq3qqqDQbd7kkQRgwGzVr0uVg7ZfS
26qSPQ0/aF9nagb5eHX3AuU=
-----END PRIVATE KEY-----

View File

@@ -0,0 +1,12 @@
[req]
default_bits = 2048
prompt = no
default_md = sha256
encrypt_key = no
distinguished_name = dn
[dn]
C = US # country code
O = Python Software Foundation # organization
OU = python-requests # organization unit/department
CN = Self-Signed Root CA # common name / your cert name

View File

@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDWzCCAkMCFA9wdtNh/V99DRwYp8vXjPxSjJnWMA0GCSqGSIb3DQEBCwUAMGox
CzAJBgNVBAYTAlVTMSMwIQYDVQQKDBpQeXRob24gU29mdHdhcmUgRm91bmRhdGlv
bjEYMBYGA1UECwwPcHl0aG9uLXJlcXVlc3RzMRwwGgYDVQQDDBNTZWxmLVNpZ25l
ZCBSb290IENBMB4XDTI0MDMxMjIxMDQwM1oXDTQ0MDMwNzIxMDQwM1owajELMAkG
A1UEBhMCVVMxIzAhBgNVBAoMGlB5dGhvbiBTb2Z0d2FyZSBGb3VuZGF0aW9uMRgw
FgYDVQQLDA9weXRob24tcmVxdWVzdHMxHDAaBgNVBAMME1NlbGYtU2lnbmVkIFJv
b3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDHlIhe7GLCeSk8
RZOKdtmyKns6KdZgGw/LcxPkYvQlu1g0zV8X0DqVr2LdMumWUTNCc9sPdSlAG+He
mQp2TMoWUMumMuwDtit9RT0Sb6Eh9svWgjY9ferovPJRfCWUTsA2Ug8uoh0wyEXK
na7X6fHt5E3B9vj0+b9a4vDibdBXV11FheLT02/uEmAEJDdP/zeBgvVbhcVyumO6
fAGMIWzR2ukhe8z/ma5H9zoi4gZA8nsK6reZUD8+6affnPe+jIt/AdzggtV9jkWm
zSpr+RHeZ0y+q4eik2ZNUGg4XcF6JsJ9yu/AqLBXxd38uLdFfgyhP2y6K628yzgy
e6lzFyWnAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGymNVTsKSAq8Ju6zV+AWAyV
GcUNBmLpgzDA0e7pkVYhHTdWKlGH4GnrRcp0nvnSbr6iq1Ob/8yEUUoRzK55Flws
Kt1OLwnZyhfRoSUesoEqpP68vzWEgiYv0QuIWvzNt0YfAAvEgGoc3iri44MelKLn
9ZMT8m91nVamA35R8ZjfeAkNp2xcz0a67V0ww6o4wSXrG7o5ZRXyjqZ/9K7SfwUJ
rV9RciccsjH/MzKbfrx73QwsbPWiFmjzHopdasIO0lDlmgm/r9gKfkbzfKoGCgLZ
6an6FlmLftLSXijf/QwtqeSP9fODeE3dzBmnTM3jdoVS53ZegUDWNl14o25v2Kg=
-----END CERTIFICATE-----

View File

@@ -0,0 +1 @@
4F36C3A7E075BA6452D10EEB81E7F189FF489B74

View File

@@ -0,0 +1,16 @@
.PHONY: all clean
server.key:
openssl genrsa -out $@ 2048
server.csr: server.key
openssl req -key $< -new -out $@ -config cert.cnf
server.pem: server.csr
openssl x509 -req -CA ../ca/ca.crt -CAkey ../ca/ca-private.key -in server.csr -outform PEM -out server.pem -days 0 -CAcreateserial
openssl x509 -in ../ca/ca.crt -outform PEM >> $@
all: server.pem
clean:
rm -f server.*

View File

@@ -0,0 +1,24 @@
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
prompt=no
[req_distinguished_name]
C = US
ST = DE
O = Python Software Foundation
OU = python-requests
CN = localhost
[v3_req]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.1 = localhost
IP.1 = 127.0.0.1
IP.2 = ::1

View File

@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIDHjCCAgYCAQAwbTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkRFMSMwIQYDVQQK
DBpQeXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEYMBYGA1UECwwPcHl0aG9uLXJl
cXVlc3RzMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQCKulIMpo633iCgbkKv1UoiLC4sQt5xWpgguujywu3hLYwmPFp9
kvPt//imqtl8FhuhKqJ8FCGr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umWUTNCc9sPdSlAG+He
mQp2TMoWUMumMuwDtit9RT0Sb6Eh9svWgjY9ferovPJRfCWUTsA2Ug8uoh0wyEXK
na7X6fHt5E3B9vj0+b9a4vDibdBXV11FheLT02/uEmAEJDdP/zeBgvVbhcVyumO6
fAGMIWzR2ukhe8z/ma5H9zoi4gZA8nsK6reZUD8+6affnPe+jIt/AdzggtV9jkWm
zSpr+RHeZ0y+q4eik2ZNUGg4XcF6JsJ9yu/AqLBXxd38uLdFfgyhP2y6K628yzgy
e6lzFyWnAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGymNVTsKSAq8Ju6zV+AWAyV
GcUNBmLpgzDA0e7pkVYhHTdWKlGH4GnrRcp0nvnSbr6iq1Ob/8yEUUoRzK55Flws
Kt1OLwnZyhfRoSUesoEqpP68vzWEgiYv0QuIWvzNt0YfAAvEgGoc3iri44MelKLn
9ZMT8m91nVamA35R8ZjfeAkNp2xcz0a67V0ww6o4wSXrG7o5ZRXyjqZ/9K7SfwUJ
rV9RciccsjH/MzKbfrx73QwsbPWiFmjzHopdasIO0lDlmgm/r9gKfkbzfKoGCgLZ
6an6FlmLftLSXijf/QwtqeSP9fODeE3dzBmnTM3jdoVS53ZegUDWNl14o25v2Kg=
-----END CERTIFICATE-----

View File

@@ -0,0 +1,7 @@
.PHONY: all clean
all:
make -C client all
clean:
make -C client clean

View File

@@ -0,0 +1,4 @@
# Certificate Examples for mTLS
This has some generated certificates for mTLS utilization. The idea is to be
able to have testing around how Requests handles client certificates.

View File

@@ -0,0 +1,16 @@
.PHONY: all clean
client.key:
openssl genrsa -out $@ 2048
client.csr: client.key
openssl req -key $< -new -out $@ -config cert.cnf
client.pem: client.csr
openssl x509 -req -CA ./ca/ca.crt -CAkey ./ca/ca-private.key -in client.csr -outform PEM -out client.pem -days 730 -CAcreateserial
openssl x509 -in ./ca/ca.crt -outform PEM >> $@
all: client.pem
clean:
rm -f client.*

1
tests/certs/mtls/client/ca Symbolic link
View File

@@ -0,0 +1 @@
../../expired/ca/

View File

@@ -0,0 +1,26 @@
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
prompt=no
[req_distinguished_name]
C = US
ST = DE
O = Python Software Foundation
OU = python-requests
CN = requests
[v3_req]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
IP.1 = 127.0.0.1
IP.2 = ::1
URI.1 = spiffe://trust.python.org/v0/maintainer/sigmavirus24/project/requests/org/psf
URI.2 = spiffe://trust.python.org/v1/maintainer:sigmavirus24/project:requests/org:psf
URI.3 = spiffe://trust.python.org/v1/maintainer=sigmavirus24/project=requests/org=psf

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIEGjCCAwICAQAwbDELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkRFMSMwIQYDVQQK
DBpQeXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEYMBYGA1UECwwPcHl0aG9uLXJl
cXVlc3RzMREwDwYDVQQDDAhyZXF1ZXN0czCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAMn3iQycTjUzpKJChRNkcm33UB282cUwpxeqKN4ahHxBpS09HRhk
cQYO7yErEUQwzQnBQEcIpzzeIMZIqHuCkgnySjeEJd95AIzNzGyoLLkS51TcJwgR
v83AvT8ljA88s9h38qGTy4/TCxJgf76pfHIuC1qoKVQh3AuHj9nOxIZLUsrdDbWF
WoLqKSVyTby+RXvSAppAR+cuBCaWStQ6xFORn48RHfc6t30ggD4rDAjyU6Vz6oR8
ot3XmGdK0h42UdqidUWkRJajEbpkCnQSXS21IvfXKxF5sFqAXJrj9iVbUfpNPpaa
W8IrHByngyV8amazGZrASstUVRFtWrnrcWECAwEAAaCCAWcwggFjBgkqhkiG9w0B
CQ4xggFUMIIBUDAJBgNVHRMEAjAAMAsGA1UdDwQEAwIFoDATBgNVHSUEDDAKBggr
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JRfCWUTsA2Ug8uoh0wyEXK
na7X6fHt5E3B9vj0+b9a4vDibdBXV11FheLT02/uEmAEJDdP/zeBgvVbhcVyumO6
fAGMIWzR2ukhe8z/ma5H9zoi4gZA8nsK6reZUD8+6affnPe+jIt/AdzggtV9jkWm
zSpr+RHeZ0y+q4eik2ZNUGg4XcF6JsJ9yu/AqLBXxd38uLdFfgyhP2y6K628yzgy
e6lzFyWnAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGymNVTsKSAq8Ju6zV+AWAyV
GcUNBmLpgzDA0e7pkVYhHTdWKlGH4GnrRcp0nvnSbr6iq1Ob/8yEUUoRzK55Flws
Kt1OLwnZyhfRoSUesoEqpP68vzWEgiYv0QuIWvzNt0YfAAvEgGoc3iri44MelKLn
9ZMT8m91nVamA35R8ZjfeAkNp2xcz0a67V0ww6o4wSXrG7o5ZRXyjqZ/9K7SfwUJ
rV9RciccsjH/MzKbfrx73QwsbPWiFmjzHopdasIO0lDlmgm/r9gKfkbzfKoGCgLZ
6an6FlmLftLSXijf/QwtqeSP9fODeE3dzBmnTM3jdoVS53ZegUDWNl14o25v2Kg=
-----END CERTIFICATE-----

1
tests/certs/valid/ca Symbolic link
View File

@@ -0,0 +1 @@
../expired/ca

View File

@@ -0,0 +1,16 @@
.PHONY: all clean
server.key:
openssl genrsa -out $@ 2048
server.csr: server.key
openssl req -key $< -config cert.cnf -new -out $@
server.pem: server.csr
openssl x509 -req -CA ../ca/ca.crt -CAkey ../ca/ca-private.key -in server.csr -outform PEM -out server.pem -extfile cert.cnf -extensions v3_ca -days 7200 -CAcreateserial
openssl x509 -in ../ca/ca.crt -outform PEM >> $@
all: server.pem
clean:
rm -f server.*

View File

@@ -0,0 +1,31 @@
[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name
prompt=no
[req_distinguished_name]
C = US
ST = DE
O = Python Software Foundation
OU = python-requests
CN = localhost
[v3_req]
# Extensions to add to a certificate request
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = critical, serverAuth
subjectAltName = critical, @alt_names
[v3_ca]
# Extensions to add to a certificate request
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = critical, serverAuth
subjectAltName = critical, @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.1 = localhost
IP.1 = 127.0.0.1
IP.2 = ::1

View File

@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE REQUEST-----
MIIDKjCCAhICAQAwbTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkRFMSMwIQYDVQQK
DBpQeXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEYMBYGA1UECwwPcHl0aG9uLXJl
cXVlc3RzMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQChEKOx377ymuDg23By5Re1DHi2RiBKSHr85/ZTZuwP/69lHN7q
TQEO//EMEFZ9+ZwezeJJsejjP2HO5lQZbcsWok3hbM0wVT+vApkogPvJ8WNFFWFe
ZBnGLi/1WM9cSZpUsDJ0XCsG0RTtO27wfgZQlKQMZxTkfi971oPYxNVSjTm2JcLT
kvwYIwxjJXPDTOgRo9TEAY3cWkCrBJN4w74GWBTM5KDDA230T7WwLuv81XD2LvYj
YYdMBGcxPr5tYTIlp3LncbcrDRNk3pbYQk0bRJgkw2vUkteiRGjkt+dgVnLc6+MI
W+VLXEpj+zsOZ5/R4d1pofqj9sDyDPhtNr1JAgMBAAGgeDB2BgkqhkiG9w0BCQ4x
aTBnMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgWgMBYGA1UdJQEB/wQMMAoG
CCsGAQUFBwMBMC8GA1UdEQEB/wQlMCOCCWxvY2FsaG9zdIcEfwAAAYcQAAAAAAAA
AAAAAAAAAAAAATANBgkqhkiG9w0BAQsFAAOCAQEAFTlFTn5Mn8JXtqB5bGjuiChe
ClA6Y32Co4l7N0CtAlf+bExwLdpLO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ibdBXV11FheLT02/uEmAEJDdP/zeBgvVbhcVyumO6
fAGMIWzR2ukhe8z/ma5H9zoi4gZA8nsK6reZUD8+6affnPe+jIt/AdzggtV9jkWm
zSpr+RHeZ0y+q4eik2ZNUGg4XcF6JsJ9yu/AqLBXxd38uLdFfgyhP2y6K628yzgy
e6lzFyWnAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGymNVTsKSAq8Ju6zV+AWAyV
GcUNBmLpgzDA0e7pkVYhHTdWKlGH4GnrRcp0nvnSbr6iq1Ob/8yEUUoRzK55Flws
Kt1OLwnZyhfRoSUesoEqpP68vzWEgiYv0QuIWvzNt0YfAAvEgGoc3iri44MelKLn
9ZMT8m91nVamA35R8ZjfeAkNp2xcz0a67V0ww6o4wSXrG7o5ZRXyjqZ/9K7SfwUJ
rV9RciccsjH/MzKbfrx73QwsbPWiFmjzHopdasIO0lDlmgm/r9gKfkbzfKoGCgLZ
6an6FlmLftLSXijf/QwtqeSP9fODeE3dzBmnTM3jdoVS53ZegUDWNl14o25v2Kg=
-----END CERTIFICATE-----

8
tests/test_adapters.py Normal file
View File

@@ -0,0 +1,8 @@
import requests.adapters
def test_request_url_trims_leading_path_separators():
"""See also https://github.com/psf/requests/issues/6643."""
a = requests.adapters.HTTPAdapter()
p = requests.Request(method="GET", url="http://127.0.0.1:10000//v:h").prepare()
assert "/v:h" == a.request_url(p, {})

View File

@@ -1,3 +1,5 @@
from unittest import mock
from requests.help import info
@@ -11,15 +13,15 @@ class VersionedPackage:
self.__version__ = version
def test_idna_without_version_attribute(mocker):
def test_idna_without_version_attribute():
"""Older versions of IDNA don't provide a __version__ attribute, verify
that if we have such a package, we don't blow up.
"""
mocker.patch("requests.help.idna", new=None)
assert info()["idna"] == {"version": ""}
with mock.patch("requests.help.idna", new=None):
assert info()["idna"] == {"version": ""}
def test_idna_with_version_attribute(mocker):
def test_idna_with_version_attribute():
"""Verify we're actually setting idna version when it should be available."""
mocker.patch("requests.help.idna", new=VersionedPackage("2.6"))
assert info()["idna"] == {"version": "2.6"}
with mock.patch("requests.help.idna", new=VersionedPackage("2.6")):
assert info()["idna"] == {"version": "2.6"}

View File

@@ -7,7 +7,9 @@ import json
import os
import pickle
import re
import threading
import warnings
from unittest import mock
import pytest
import urllib3
@@ -50,6 +52,7 @@ from requests.structures import CaseInsensitiveDict
from . import SNIMissingWarning
from .compat import StringIO
from .testserver.server import TLSServer, consume_socket_content
from .utils import override_environ
# Requests to this URL should always fail with a connection timeout (nothing
@@ -75,11 +78,9 @@ except AttributeError:
class TestRequests:
digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
def test_entry_points(self):
requests.session
requests.session().get
requests.session().head
@@ -510,7 +511,6 @@ class TestRequests:
@pytest.mark.parametrize("key", ("User-agent", "user-agent"))
def test_user_agent_transfers(self, httpbin, key):
heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}
r = requests.get(httpbin("user-agent"), headers=heads)
@@ -647,25 +647,26 @@ class TestRequests:
assert sent_headers.get("Proxy-Authorization") == proxy_auth_value
@pytest.mark.parametrize(
"url,has_proxy_auth",
(
('http://example.com', True),
('https://example.com', False),
("http://example.com", True),
("https://example.com", False),
),
)
def test_proxy_authorization_not_appended_to_https_request(self, url, has_proxy_auth):
def test_proxy_authorization_not_appended_to_https_request(
self, url, has_proxy_auth
):
session = requests.Session()
proxies = {
'http': 'http://test:pass@localhost:8080',
'https': 'http://test:pass@localhost:8090',
"http": "http://test:pass@localhost:8080",
"https": "http://test:pass@localhost:8090",
}
req = requests.Request('GET', url)
req = requests.Request("GET", url)
prep = req.prepare()
session.rebuild_proxies(prep, proxies)
assert ('Proxy-Authorization' in prep.headers) is has_proxy_auth
assert ("Proxy-Authorization" in prep.headers) is has_proxy_auth
def test_basicauth_with_netrc(self, httpbin):
auth = ("user", "pass")
@@ -703,7 +704,6 @@ class TestRequests:
requests.sessions.get_netrc_auth = old_auth
def test_DIGEST_HTTP_200_OK_GET(self, httpbin):
for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")
@@ -721,7 +721,6 @@ class TestRequests:
assert r.status_code == 200
def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):
for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass")
@@ -732,7 +731,6 @@ class TestRequests:
assert r.status_code == 200
def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):
for authtype in self.digest_auth_algo:
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
auth = HTTPDigestAuth("user", "pass")
@@ -741,7 +739,6 @@ class TestRequests:
assert s.cookies["fake"] == "fake_value"
def test_DIGEST_STREAM(self, httpbin):
for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -753,7 +750,6 @@ class TestRequests:
assert r.raw.read() == b""
def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):
for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "wrongpass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -770,7 +766,6 @@ class TestRequests:
assert r.status_code == 401
def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):
for authtype in self.digest_auth_algo:
auth = HTTPDigestAuth("user", "pass")
url = httpbin("digest-auth", "auth", "user", "pass", authtype)
@@ -779,7 +774,6 @@ class TestRequests:
assert '"auth"' in r.request.headers["Authorization"]
def test_POSTBIN_GET_POST_FILES(self, httpbin):
url = httpbin("post")
requests.post(url).raise_for_status()
@@ -797,7 +791,6 @@ class TestRequests:
requests.post(url, files=["bad file data"])
def test_invalid_files_input(self, httpbin):
url = httpbin("post")
post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})
assert b'name="random-file-1"' not in post.request.body
@@ -845,7 +838,6 @@ class TestRequests:
assert post2.json()["data"] == "st"
def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):
url = httpbin("post")
requests.post(url).raise_for_status()
@@ -983,12 +975,12 @@ class TestRequests:
),
),
)
def test_env_cert_bundles(self, httpbin, mocker, env, expected):
def test_env_cert_bundles(self, httpbin, env, expected):
s = requests.Session()
mocker.patch("os.environ", env)
settings = s.merge_environment_settings(
url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None
)
with mock.patch("os.environ", env):
settings = s.merge_environment_settings(
url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None
)
assert settings["verify"] == expected
def test_http_with_certificate(self, httpbin):
@@ -1011,7 +1003,7 @@ class TestRequests:
"SubjectAltNameWarning",
)
with pytest.warns(None) as warning_records:
with pytest.warns() as warning_records:
warnings.simplefilter("always")
requests.get(f"https://localhost:{port}/", verify=ca_bundle)
@@ -1034,7 +1026,6 @@ class TestRequests:
requests.get(httpbin_secure("status", "200"))
def test_urlencoded_get_query_multivalued_param(self, httpbin):
r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
assert r.status_code == 200
assert r.url == httpbin("get?test=foo&test=baz")
@@ -1476,11 +1467,9 @@ class TestRequests:
(urllib3.exceptions.SSLError, tuple(), RequestsSSLError),
),
)
def test_iter_content_wraps_exceptions(
self, httpbin, mocker, exception, args, expected
):
def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):
r = requests.Response()
r.raw = mocker.Mock()
r.raw = mock.Mock()
# ReadTimeoutError can't be initialized by mock
# so we'll manually create the instance with args
r.raw.stream.side_effect = exception(*args)
@@ -1715,7 +1704,7 @@ class TestRequests:
}
r = requests.get(httpbin("get"), headers=valid_headers)
for key in valid_headers.keys():
valid_headers[key] == r.request.headers[key]
assert valid_headers[key] == r.request.headers[key]
@pytest.mark.parametrize(
"invalid_header, key",
@@ -1821,6 +1810,23 @@ class TestRequests:
assert p.headers["Content-Length"] == length
def test_content_length_for_bytes_data(self, httpbin):
data = "This is a string containing multi-byte UTF-8 ☃️"
encoded_data = data.encode("utf-8")
length = str(len(encoded_data))
req = requests.Request("POST", httpbin("post"), data=encoded_data)
p = req.prepare()
assert p.headers["Content-Length"] == length
def test_content_length_for_string_data_counts_bytes(self, httpbin):
data = "This is a string containing multi-byte UTF-8 ☃️"
length = str(len(data.encode("utf-8")))
req = requests.Request("POST", httpbin("post"), data=data)
p = req.prepare()
assert p.headers["Content-Length"] == length
def test_nonhttp_schemes_dont_check_URLs(self):
test_urls = (
"data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
@@ -2105,16 +2111,16 @@ class TestRequests:
next(r.iter_lines())
assert len(list(r.iter_lines())) == 3
def test_session_close_proxy_clear(self, mocker):
def test_session_close_proxy_clear(self):
proxies = {
"one": mocker.Mock(),
"two": mocker.Mock(),
"one": mock.Mock(),
"two": mock.Mock(),
}
session = requests.Session()
mocker.patch.dict(session.adapters["http://"].proxy_manager, proxies)
session.close()
proxies["one"].clear.assert_called_once_with()
proxies["two"].clear.assert_called_once_with()
with mock.patch.dict(session.adapters["http://"].proxy_manager, proxies):
session.close()
proxies["one"].clear.assert_called_once_with()
proxies["two"].clear.assert_called_once_with()
def test_proxy_auth(self):
adapter = HTTPAdapter()
@@ -2715,7 +2721,7 @@ class TestPreparingURLs:
with pytest.raises(requests.exceptions.InvalidURL):
r.prepare()
@pytest.mark.parametrize("url, exception", (("http://localhost:-1", InvalidURL),))
@pytest.mark.parametrize("url, exception", (("http://:1", InvalidURL),))
def test_redirecting_to_bad_url(self, httpbin, url, exception):
with pytest.raises(exception):
requests.get(httpbin("redirect-to"), params={"url": url})
@@ -2808,3 +2814,163 @@ class TestPreparingURLs:
with pytest.raises(requests.exceptions.JSONDecodeError) as excinfo:
r.json()
assert excinfo.value.doc == r.text
def test_status_code_425(self):
r1 = requests.codes.get("TOO_EARLY")
r2 = requests.codes.get("too_early")
r3 = requests.codes.get("UNORDERED")
r4 = requests.codes.get("unordered")
r5 = requests.codes.get("UNORDERED_COLLECTION")
r6 = requests.codes.get("unordered_collection")
assert r1 == 425
assert r2 == 425
assert r3 == 425
assert r4 == 425
assert r5 == 425
assert r6 == 425
def test_different_connection_pool_for_tls_settings_verify_True(self):
def response_handler(sock):
consume_socket_content(sock, timeout=0.5)
sock.send(
b"HTTP/1.1 200 OK\r\n"
b"Content-Length: 18\r\n\r\n"
b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'
)
s = requests.Session()
close_server = threading.Event()
server = TLSServer(
handler=response_handler,
wait_to_close_event=close_server,
requests_to_handle=3,
cert_chain="tests/certs/expired/server/server.pem",
keyfile="tests/certs/expired/server/server.key",
)
with server as (host, port):
url = f"https://{host}:{port}"
r1 = s.get(url, verify=False)
assert r1.status_code == 200
# Cannot verify self-signed certificate
with pytest.raises(requests.exceptions.SSLError):
s.get(url)
close_server.set()
assert 2 == len(s.adapters["https://"].poolmanager.pools)
def test_different_connection_pool_for_tls_settings_verify_bundle_expired_cert(
self,
):
def response_handler(sock):
consume_socket_content(sock, timeout=0.5)
sock.send(
b"HTTP/1.1 200 OK\r\n"
b"Content-Length: 18\r\n\r\n"
b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'
)
s = requests.Session()
close_server = threading.Event()
server = TLSServer(
handler=response_handler,
wait_to_close_event=close_server,
requests_to_handle=3,
cert_chain="tests/certs/expired/server/server.pem",
keyfile="tests/certs/expired/server/server.key",
)
with server as (host, port):
url = f"https://{host}:{port}"
r1 = s.get(url, verify=False)
assert r1.status_code == 200
# Has right trust bundle, but certificate expired
with pytest.raises(requests.exceptions.SSLError):
s.get(url, verify="tests/certs/expired/ca/ca.crt")
close_server.set()
assert 2 == len(s.adapters["https://"].poolmanager.pools)
def test_different_connection_pool_for_tls_settings_verify_bundle_unexpired_cert(
self,
):
def response_handler(sock):
consume_socket_content(sock, timeout=0.5)
sock.send(
b"HTTP/1.1 200 OK\r\n"
b"Content-Length: 18\r\n\r\n"
b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'
)
s = requests.Session()
close_server = threading.Event()
server = TLSServer(
handler=response_handler,
wait_to_close_event=close_server,
requests_to_handle=3,
cert_chain="tests/certs/valid/server/server.pem",
keyfile="tests/certs/valid/server/server.key",
)
with server as (host, port):
url = f"https://{host}:{port}"
r1 = s.get(url, verify=False)
assert r1.status_code == 200
r2 = s.get(url, verify="tests/certs/valid/ca/ca.crt")
assert r2.status_code == 200
close_server.set()
assert 2 == len(s.adapters["https://"].poolmanager.pools)
def test_different_connection_pool_for_mtls_settings(self):
client_cert = None
def response_handler(sock):
nonlocal client_cert
client_cert = sock.getpeercert()
consume_socket_content(sock, timeout=0.5)
sock.send(
b"HTTP/1.1 200 OK\r\n"
b"Content-Length: 18\r\n\r\n"
b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'
)
s = requests.Session()
close_server = threading.Event()
server = TLSServer(
handler=response_handler,
wait_to_close_event=close_server,
requests_to_handle=2,
cert_chain="tests/certs/expired/server/server.pem",
keyfile="tests/certs/expired/server/server.key",
mutual_tls=True,
cacert="tests/certs/expired/ca/ca.crt",
)
cert = (
"tests/certs/mtls/client/client.pem",
"tests/certs/mtls/client/client.key",
)
with server as (host, port):
url = f"https://{host}:{port}"
r1 = s.get(url, verify=False, cert=cert)
assert r1.status_code == 200
with pytest.raises(requests.exceptions.SSLError):
s.get(url, cert=cert)
close_server.set()
assert client_cert is not None
def test_json_decode_errors_are_serializable_deserializable():
json_decode_error = requests.exceptions.JSONDecodeError(
"Extra data",
'{"responseCode":["706"],"data":null}{"responseCode":["706"],"data":null}',
36,
)
deserialized_error = pickle.loads(pickle.dumps(json_decode_error))
assert repr(json_decode_error) == repr(deserialized_error)

View File

@@ -5,6 +5,7 @@ import tarfile
import zipfile
from collections import deque
from io import BytesIO
from unittest import mock
import pytest
@@ -751,13 +752,13 @@ def test_should_bypass_proxies(url, expected, monkeypatch):
("http://user:pass@hostname:5000", "hostname"),
),
)
def test_should_bypass_proxies_pass_only_hostname(url, expected, mocker):
def test_should_bypass_proxies_pass_only_hostname(url, expected):
"""The proxy_bypass function should be called with a hostname or IP without
a port number or auth credentials.
"""
proxy_bypass = mocker.patch("requests.utils.proxy_bypass")
should_bypass_proxies(url, no_proxy=None)
proxy_bypass.assert_called_once_with(expected)
with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:
should_bypass_proxies(url, no_proxy=None)
proxy_bypass.assert_called_once_with(expected)
@pytest.mark.parametrize(
@@ -923,3 +924,35 @@ def test_set_environ_raises_exception():
raise Exception("Expected exception")
assert "Expected exception" in str(exception.value)
@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")
def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):
"""Tests for function should_bypass_proxies to check if proxy
can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.
"""
import winreg
class RegHandle:
def Close(self):
pass
ie_settings = RegHandle()
def OpenKey(key, subkey):
return ie_settings
def QueryValueEx(key, value_name):
if key is ie_settings:
if value_name == "ProxyEnable":
return [1]
elif value_name == "ProxyOverride":
return [
"192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"
]
monkeypatch.setenv("NO_PROXY", "")
monkeypatch.setenv("no_proxy", "")
monkeypatch.setattr(winreg, "OpenKey", OpenKey)
monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)
assert should_bypass_proxies("http://example.com/", None) is False

View File

@@ -1,5 +1,6 @@
import select
import socket
import ssl
import threading
@@ -132,3 +133,44 @@ class Server(threading.Thread):
self._close_server_sock_ignore_errors()
self.join()
return False # allow exceptions to propagate
class TLSServer(Server):
def __init__(
self,
*,
handler=None,
host="localhost",
port=0,
requests_to_handle=1,
wait_to_close_event=None,
cert_chain=None,
keyfile=None,
mutual_tls=False,
cacert=None,
):
super().__init__(
handler=handler,
host=host,
port=port,
requests_to_handle=requests_to_handle,
wait_to_close_event=wait_to_close_event,
)
self.cert_chain = cert_chain
self.keyfile = keyfile
self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
self.ssl_context.load_cert_chain(self.cert_chain, keyfile=self.keyfile)
self.mutual_tls = mutual_tls
self.cacert = cacert
if mutual_tls:
# For simplicity, we're going to assume that the client cert is
# issued by the same CA as our Server certificate
self.ssl_context.verify_mode = ssl.CERT_OPTIONAL
self.ssl_context.load_verify_locations(self.cacert)
def _create_socket_and_bind(self):
sock = socket.socket()
sock = self.ssl_context.wrap_socket(sock, server_side=True)
sock.bind((self.host, self.port))
sock.listen()
return sock

View File

@@ -1,5 +1,5 @@
[tox]
envlist = py{37,38,39,310,311}-{default, use_chardet_on_py3}
envlist = py{38,39,310,311,312}-{default, use_chardet_on_py3}
[testenv]
deps = -rrequirements-dev.txt
@@ -7,7 +7,7 @@ extras =
security
socks
commands =
pytest tests
pytest {posargs:tests}
[testenv:default]