Skip to content
Myr

test_requests.py

This file

Path

tests/test_requests.py

3,039 lines · 104.1 KiB · Python

Last changed by

Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f

History of this file

Take it

The walk stopped after 200 commits: lines older than 24dfbfd point at it.

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1why, one step back
1"""Tests for Requests."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 2why, one step back
2

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 3–5why, one step back
3import collections
4import contextlib5import io

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 6–9why, one step back
6import json
7import os8import pickle9import re

Add new test to check netrc auth leak (#6962)danigmbefore adoption7bc4587

line 10why, one step back
10import tempfile

Merge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a

line 11why, one step back
11import threading

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 12why, one step back
12import warnings

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 13why, one step back
13from unittest import mock

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 14why, one step back
14

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 15why, one step back
15import pytest

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 16why, one step back
16import urllib3

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 17why, one step back
17from urllib3.util import Timeout as Urllib3Timeout

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 18–28why, one step back
18
19import requests20from requests.adapters import HTTPAdapter21from requests.auth import HTTPDigestAuth, _basic_auth_str22from requests.compat import (23 JSONDecodeError,24 Morsel,25 MutableMapping,26 builtin_str,27 cookielib,28 getproxies,

Merge pull request #6757 from nateprewitt/urllib-1.x-testsNate Prewittbefore adoption79b74ef

line 29why, one step back
29 is_urllib3_1,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 30–46why, one step back
30 urlparse,
31)32from requests.cookies import cookiejar_from_dict, morsel_to_cookie33from requests.exceptions import (34 ChunkedEncodingError,35 ConnectionError,36 ConnectTimeout,37 ContentDecodingError,38 InvalidHeader,39 InvalidProxyURL,40 InvalidSchema,41 InvalidURL,42 MissingSchema,43 ProxyError,44 ReadTimeout,45 RequestException,46 RetryError,

Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f

lines 47–49why, one step back
47 Timeout,
48 TooManyRedirects,49 UnrewindableBodyError,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 50–56why, one step back
50)
51from requests.exceptions import SSLError as RequestsSSLError52from requests.hooks import default_hooks53from requests.models import PreparedRequest, urlencode54from requests.sessions import SessionRedirectMixin55from requests.structures import CaseInsensitiveDict56

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

line 57why, one step back
57from . import SNIMissingWarning

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 58why, one step back
58from .compat import StringIO

Merge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a

line 59why, one step back
59from .testserver.server import TLSServer, consume_socket_content

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 60–61why, one step back
60from .utils import override_environ
61

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 62–63why, one step back
62# Requests to this URL should always fail with a connection timeout (nothing
63# listening on that port)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 64–65why, one step back
64TARPIT = "http://10.255.255.1"
65

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 66why, one step back
66# This is to avoid waiting the timeout of using TARPIT

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 67–69why, one step back
67INVALID_PROXY = "http://localhost:1"
6869try:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 70why, one step back
70 from ssl import SSLContext

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 71why, one step back
71

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 72–75why, one step back
72 del SSLContext
73 HAS_MODERN_SSL = True74except ImportError:75 HAS_MODERN_SSL = False

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 76–77why, one step back
76
77try:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 78–81why, one step back
78 requests.pyopenssl
79 HAS_PYOPENSSL = True80except AttributeError:81 HAS_PYOPENSSL = False

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 82–83why, one step back
82
83

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 84why, one step back
84class TestRequests:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 85–86why, one step back
85 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
86

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 87–96why, one step back
87 def test_entry_points(self):
88 requests.session89 requests.session().get90 requests.session().head91 requests.get92 requests.head93 requests.put94 requests.patch95 requests.post96 # Not really an entry point, but people rely on it.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 97–110why, one step back
97 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F401
9899 @pytest.mark.parametrize(100 "exception, url",101 (102 (MissingSchema, "hiwpefhipowhefopw"),103 (InvalidSchema, "localhost:3128"),104 (InvalidSchema, "localhost.localdomain:3128/"),105 (InvalidSchema, "10.122.1.1:3128/"),106 (InvalidURL, "http://"),107 (InvalidURL, "http://*example.com"),108 (InvalidURL, "http://.example.com"),109 ),110 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 111why, one step back
111 def test_invalid_url(self, exception, url):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 112why, one step back
112 with pytest.raises(exception):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 113why, one step back
113 requests.get(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 114why, one step back
114

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 115–116why, one step back
115 def test_basic_building(self):
116 req = requests.Request()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 117–119why, one step back
117 req.url = "http://kennethreitz.org/"
118 req.data = {"life": "42"}119

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 120–121why, one step back
120 pr = req.prepare()
121 assert pr.url == req.url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 122–124why, one step back
122 assert pr.body == "life=42"
123124 @pytest.mark.parametrize("method", ("GET", "HEAD"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 125why, one step back
125 def test_no_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 126–129why, one step back
126 req = requests.Request(method, httpbin(method.lower())).prepare()
127 assert "Content-Length" not in req.headers128129 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 130why, one step back
130 def test_no_body_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 131–134why, one step back
131 req = requests.Request(method, httpbin(method.lower())).prepare()
132 assert req.headers["Content-Length"] == "0"133134 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 135why, one step back
135 def test_empty_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 136–138why, one step back
136 req = requests.Request(method, httpbin(method.lower()), data="").prepare()
137 assert req.headers["Content-Length"] == "0"138

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 139why, one step back
139 def test_override_content_length(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 140–144why, one step back
140 headers = {"Content-Length": "not zero"}
141 r = requests.Request("POST", httpbin("post"), headers=headers).prepare()142 assert "Content-Length" in r.headers143 assert r.headers["Content-Length"] == "not zero"144

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 145why, one step back
145 def test_path_is_not_double_encoded(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 146–162why, one step back
146 request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()
147148 assert request.path_url == "/get/test%20case"149150 @pytest.mark.parametrize(151 "url, expected",152 (153 (154 "http://example.com/path#fragment",155 "http://example.com/path?a=b#fragment",156 ),157 (158 "http://example.com/path?key=value#fragment",159 "http://example.com/path?key=value&a=b#fragment",160 ),161 ),162 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 163why, one step back
163 def test_params_are_added_before_fragment(self, url, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 164why, one step back
164 request = requests.Request("GET", url, params={"a": "b"}).prepare()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 165why, one step back
165 assert request.url == expected

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 166why, one step back
166

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 167why, one step back
167 def test_params_original_order_is_preserved_by_default(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 168–174why, one step back
168 param_ordered_dict = collections.OrderedDict(
169 (("z", 1), ("a", 1), ("k", 1), ("d", 1))170 )171 session = requests.Session()172 request = requests.Request(173 "GET", "http://example.com/", params=param_ordered_dict174 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 175why, one step back
175 prep = session.prepare_request(request)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 176–177why, one step back
176 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"
177

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 178why, one step back
178 def test_params_bytes_are_encoded(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 179–183why, one step back
179 request = requests.Request(
180 "GET", "http://example.com", params=b"test=foo"181 ).prepare()182 assert request.url == "http://example.com/?test=foo"183

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 184why, one step back
184 def test_binary_put(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 185–187why, one step back
185 request = requests.Request(
186 "PUT", "http://example.com", data="ööö".encode()187 ).prepare()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 188why, one step back
188 assert isinstance(request.body, bytes)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 189why, one step back
189

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 190–191why, one step back
190 def test_whitespaces_are_removed_from_url(self):
191 # Test for issue #3696

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 192–195why, one step back
192 request = requests.Request("GET", " http://example.com").prepare()
193 assert request.url == "http://example.com/"194195 @pytest.mark.parametrize("scheme", ("http://", "HTTP://", "hTTp://", "HttP://"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 196why, one step back
196 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 197–199why, one step back
197 s = requests.Session()
198 s.proxies = getproxies()199 parts = urlparse(httpbin("get"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 200why, one step back
200 url = scheme + parts.netloc + parts.path

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 201–204why, one step back
201 r = requests.Request("GET", url)
202 r = s.send(r.prepare())203 assert r.status_code == 200, f"failed for scheme {scheme}"204

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 205why, one step back
205 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 206–213why, one step back
206 r = requests.Request("GET", httpbin("get"))
207 s = requests.Session()208 s.proxies = getproxies()209210 r = s.send(r.prepare())211212 assert r.status_code == 200213

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 214why, one step back
214 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 215–219why, one step back
215 r = requests.get(httpbin("redirect", "1"))
216 assert r.status_code == 200217 assert r.history[0].status_code == 302218 assert r.history[0].is_redirect219

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 220why, one step back
220 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 221–230why, one step back
221 r = requests.post(
222 httpbin("redirect-to"),223 data="test",224 params={"url": "post", "status_code": 307},225 )226 assert r.status_code == 200227 assert r.history[0].status_code == 307228 assert r.history[0].is_redirect229 assert r.json()["data"] == "test"230

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 231why, one step back
231 def test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 232–242why, one step back
232 byte_str = b"test"
233 r = requests.post(234 httpbin("redirect-to"),235 data=io.BytesIO(byte_str),236 params={"url": "post", "status_code": 307},237 )238 assert r.status_code == 200239 assert r.history[0].status_code == 307240 assert r.history[0].is_redirect241 assert r.json()["data"] == byte_str.decode("utf-8")242

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 243why, one step back
243 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 244–249why, one step back
244 try:
245 requests.get(httpbin("relative-redirect", "50"))246 except TooManyRedirects as e:247 url = httpbin("relative-redirect", "20")248 assert e.request.url == url249 assert e.response.url == url

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 250why, one step back
250 assert len(e.response.history) == 30

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 251–253why, one step back
251 else:
252 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")253

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 254why, one step back
254 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 255why, one step back
255 s = requests.session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 256why, one step back
256 s.max_redirects = 5

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 257–262why, one step back
257 try:
258 s.get(httpbin("relative-redirect", "50"))259 except TooManyRedirects as e:260 url = httpbin("relative-redirect", "45")261 assert e.request.url == url262 assert e.response.url == url

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 263why, one step back
263 assert len(e.response.history) == 5

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 264–268why, one step back
264 else:
265 pytest.fail(266 "Expected custom max number of redirects to be respected but was not"267 )268

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 269why, one step back
269 def test_http_301_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 270–275why, one step back
270 r = requests.post(httpbin("status", "301"))
271 assert r.status_code == 200272 assert r.request.method == "GET"273 assert r.history[0].status_code == 301274 assert r.history[0].is_redirect275

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 276why, one step back
276 def test_http_301_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 277why, one step back
277 r = requests.head(httpbin("status", "301"), allow_redirects=True)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 278why, one step back
278 print(r.content)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 279–283why, one step back
279 assert r.status_code == 200
280 assert r.request.method == "HEAD"281 assert r.history[0].status_code == 301282 assert r.history[0].is_redirect283

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 284why, one step back
284 def test_http_302_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 285–290why, one step back
285 r = requests.post(httpbin("status", "302"))
286 assert r.status_code == 200287 assert r.request.method == "GET"288 assert r.history[0].status_code == 302289 assert r.history[0].is_redirect290

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 291why, one step back
291 def test_http_302_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 292–297why, one step back
292 r = requests.head(httpbin("status", "302"), allow_redirects=True)
293 assert r.status_code == 200294 assert r.request.method == "HEAD"295 assert r.history[0].status_code == 302296 assert r.history[0].is_redirect297

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 298why, one step back
298 def test_http_303_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 299–304why, one step back
299 r = requests.post(httpbin("status", "303"))
300 assert r.status_code == 200301 assert r.request.method == "GET"302 assert r.history[0].status_code == 303303 assert r.history[0].is_redirect304

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 305why, one step back
305 def test_http_303_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 306–311why, one step back
306 r = requests.head(httpbin("status", "303"), allow_redirects=True)
307 assert r.status_code == 200308 assert r.request.method == "HEAD"309 assert r.history[0].status_code == 303310 assert r.history[0].is_redirect311

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 312why, one step back
312 def test_header_and_body_removal_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 313–316why, one step back
313 purged_headers = ("Content-Length", "Content-Type")
314 ses = requests.Session()315 req = requests.Request("POST", httpbin("post"), data={"test": "data"})316 prep = ses.prepare_request(req)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 317why, one step back
317 resp = ses.send(prep)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 318–322why, one step back
318
319 # Mimic a redirect response320 resp.status_code = 302321 resp.headers["location"] = "get"322

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 323why, one step back
323 # Run request through resolve_redirects

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 324–328why, one step back
324 next_resp = next(ses.resolve_redirects(resp, prep))
325 assert next_resp.request.body is None326 for header in purged_headers:327 assert header not in next_resp.request.headers328

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 329why, one step back
329 def test_transfer_enc_removal_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 330–335why, one step back
330 purged_headers = ("Transfer-Encoding", "Content-Type")
331 ses = requests.Session()332 req = requests.Request("POST", httpbin("post"), data=(b"x" for x in range(1)))333 prep = ses.prepare_request(req)334 assert "Transfer-Encoding" in prep.headers335

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 336why, one step back
336 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 337–338why, one step back
337 resp = requests.Response()
338 resp.raw = io.BytesIO(b"the content")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 339why, one step back
339 resp.request = prep

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 340–345why, one step back
340 setattr(resp.raw, "release_conn", lambda *args: args)
341342 # Mimic a redirect response343 resp.status_code = 302344 resp.headers["location"] = httpbin("get")345

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 346why, one step back
346 # Run request through resolve_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 347–351why, one step back
347 next_resp = next(ses.resolve_redirects(resp, prep))
348 assert next_resp.request.body is None349 for header in purged_headers:350 assert header not in next_resp.request.headers351

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 352–353why, one step back
352 def test_fragment_maintained_on_redirect(self, httpbin):
353 fragment = "#view=edit&token=hunter2"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 354–355why, one step back
354 r = requests.get(httpbin("redirect-to?url=get") + fragment)
355

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 356why, one step back
356 assert len(r.history) > 0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 357–359why, one step back
357 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment
358 assert r.url == httpbin("get") + fragment359

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 360why, one step back
360 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 361–367why, one step back
361 heads = {"User-agent": "Mozilla/5.0"}
362363 r = requests.get(httpbin("user-agent"), headers=heads)364365 assert heads["User-agent"] in r.text366 assert r.status_code == 200367

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 368why, one step back
368 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 369–375why, one step back
369 heads = {"User-agent": "Mozilla/5.0"}
370371 r = requests.get(372 httpbin("get") + "?test=true", params={"q": "test"}, headers=heads373 )374 assert r.status_code == 200375

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 376why, one step back
376 def test_set_cookie_on_301(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 377–381why, one step back
377 s = requests.session()
378 url = httpbin("cookies/set?foo=bar")379 s.get(url)380 assert s.cookies["foo"] == "bar"381

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 382why, one step back
382 def test_cookie_sent_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 383–387why, one step back
383 s = requests.session()
384 s.get(httpbin("cookies/set?foo=bar"))385 r = s.get(httpbin("redirect/1")) # redirects to httpbin('get')386 assert "Cookie" in r.json()["headers"]387

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 388why, one step back
388 def test_cookie_removed_on_expire(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 389–391why, one step back
389 s = requests.session()
390 s.get(httpbin("cookies/set?foo=bar"))391 assert s.cookies["foo"] == "bar"

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 392why, one step back
392 s.get(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 393–397why, one step back
393 httpbin("response-headers"),
394 params={"Set-Cookie": "foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT"},395 )396 assert "foo" not in s.cookies397

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 398why, one step back
398 def test_cookie_quote_wrapped(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 399why, one step back
399 s = requests.session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 400why, one step back
400 s.get(httpbin('cookies/set?foo="bar:baz"'))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 401–402why, one step back
401 assert s.cookies["foo"] == '"bar:baz"'
402

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 403why, one step back
403 def test_cookie_persists_via_api(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 404–408why, one step back
404 s = requests.session()
405 r = s.get(httpbin("redirect/1"), cookies={"foo": "bar"})406 assert "foo" in r.request.headers["Cookie"]407 assert "foo" in r.history[0].request.headers["Cookie"]408

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 409why, one step back
409 def test_request_cookie_overrides_session_cookie(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 410–413why, one step back
410 s = requests.session()
411 s.cookies["foo"] = "bar"412 r = s.get(httpbin("cookies"), cookies={"foo": "baz"})413 assert r.json()["cookies"]["foo"] == "baz"

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 414why, one step back
414 # Session cookie should not be modified

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 415–416why, one step back
415 assert s.cookies["foo"] == "bar"
416

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 417why, one step back
417 def test_request_cookies_not_persisted(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 418–419why, one step back
418 s = requests.session()
419 s.get(httpbin("cookies"), cookies={"foo": "baz"})

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 420–421why, one step back
420 # Sending a request with cookies should not add cookies to the session
421 assert not s.cookies

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 422why, one step back
422

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 423why, one step back
423 def test_generic_cookiejar_works(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 424–426why, one step back
424 cj = cookielib.CookieJar()
425 cookiejar_from_dict({"foo": "bar"}, cj)426 s = requests.session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 427why, one step back
427 s.cookies = cj

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 428–430why, one step back
428 r = s.get(httpbin("cookies"))
429 # Make sure the cookie was sent430 assert r.json()["cookies"]["foo"] == "bar"

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 431–432why, one step back
431 # Make sure the session cj is still the custom one
432 assert s.cookies is cj

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 433why, one step back
433

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 434why, one step back
434 def test_param_cookiejar_works(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 435–441why, one step back
435 cj = cookielib.CookieJar()
436 cookiejar_from_dict({"foo": "bar"}, cj)437 s = requests.session()438 r = s.get(httpbin("cookies"), cookies=cj)439 # Make sure the cookie was sent440 assert r.json()["cookies"]["foo"] == "bar"441

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 442–444why, one step back
442 def test_cookielib_cookiejar_on_redirect(self, httpbin):
443 """Tests resolve_redirect doesn't fail when merging cookies444 with non-RequestsCookieJar cookiejar.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 445why, one step back
445

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 446why, one step back
446 See GH #3579

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 447–451why, one step back
447 """
448 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())449 s = requests.Session()450 s.cookies = cookiejar_from_dict({"cookie": "tasty"})451

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 452why, one step back
452 # Prepare request without using Session

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 453why, one step back
453 req = requests.Request("GET", httpbin("headers"), cookies=cj)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 454why, one step back
454 prep_req = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 455why, one step back
455

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 456–457why, one step back
456 # Send request and simulate redirect
457 resp = s.send(prep_req)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 458–459why, one step back
458 resp.status_code = 302
459 resp.headers["location"] = httpbin("get")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 460–461why, one step back
460 redirects = s.resolve_redirects(resp, prep_req)
461 resp = next(redirects)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 462why, one step back
462

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 463–466why, one step back
463 # Verify CookieJar isn't being converted to RequestsCookieJar
464 assert isinstance(prep_req._cookies, cookielib.CookieJar)465 assert isinstance(resp.request._cookies, cookielib.CookieJar)466 assert not isinstance(resp.request._cookies, requests.cookies.RequestsCookieJar)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 467why, one step back
467

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 468–470why, one step back
468 cookies = {}
469 for c in resp.request._cookies:470 cookies[c.name] = c.value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 471–473why, one step back
471 assert cookies["foo"] == "bar"
472 assert cookies["cookie"] == "tasty"473

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 474why, one step back
474 def test_requests_in_history_are_not_overridden(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 475why, one step back
475 resp = requests.get(httpbin("redirect/3"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 476–478why, one step back
476 urls = [r.url for r in resp.history]
477 req_urls = [r.request.url for r in resp.history]478 assert urls == req_urls

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 479why, one step back
479

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 480–481why, one step back
480 def test_history_is_always_a_list(self, httpbin):
481 """Show that even with redirects, Response.history is always a list."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 482–485why, one step back
482 resp = requests.get(httpbin("get"))
483 assert isinstance(resp.history, list)484 resp = requests.get(httpbin("redirect/1"))485 assert isinstance(resp.history, list)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 486why, one step back
486 assert not isinstance(resp.history, tuple)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 487why, one step back
487

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 488–489why, one step back
488 def test_headers_on_session_with_None_are_not_sent(self, httpbin):
489 """Do not send headers in Session.headers with None values."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 490–495why, one step back
490 ses = requests.Session()
491 ses.headers["Accept-Encoding"] = None492 req = requests.Request("GET", httpbin("get"))493 prep = ses.prepare_request(req)494 assert "Accept-Encoding" not in prep.headers495

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 496–497why, one step back
496 def test_headers_preserve_order(self, httpbin):
497 """Preserve order when headers provided as OrderedDict."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 498why, one step back
498 ses = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 499why, one step back
499 ses.headers = collections.OrderedDict()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 500–507why, one step back
500 ses.headers["Accept-Encoding"] = "identity"
501 ses.headers["First"] = "1"502 ses.headers["Second"] = "2"503 headers = collections.OrderedDict([("Third", "3"), ("Fourth", "4")])504 headers["Fifth"] = "5"505 headers["Second"] = "222"506 req = requests.Request("GET", httpbin("get"), headers=headers)507 prep = ses.prepare_request(req)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 508why, one step back
508 items = list(prep.headers.items())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 509–516why, one step back
509 assert items[0] == ("Accept-Encoding", "identity")
510 assert items[1] == ("First", "1")511 assert items[2] == ("Second", "222")512 assert items[3] == ("Third", "3")513 assert items[4] == ("Fourth", "4")514 assert items[5] == ("Fifth", "5")515516 @pytest.mark.parametrize("key", ("User-agent", "user-agent"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 517why, one step back
517 def test_user_agent_transfers(self, httpbin, key):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 518–520why, one step back
518 heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}
519520 r = requests.get(httpbin("user-agent"), headers=heads)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 521why, one step back
521 assert heads[key] in r.text

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 522why, one step back
522

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 523why, one step back
523 def test_HTTP_200_OK_HEAD(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 524–526why, one step back
524 r = requests.head(httpbin("get"))
525 assert r.status_code == 200526

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 527why, one step back
527 def test_HTTP_200_OK_PUT(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 528–530why, one step back
528 r = requests.put(httpbin("put"))
529 assert r.status_code == 200530

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 531why, one step back
531 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 532–534why, one step back
532 auth = ("user", "pass")
533 url = httpbin("basic-auth", "user", "pass")534

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 535why, one step back
535 r = requests.get(url, auth=auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 536–537why, one step back
536 assert r.status_code == 200
537

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 538–539why, one step back
538 r = requests.get(url)
539 assert r.status_code == 401

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 540–541why, one step back
540
541 s = requests.session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 542–543why, one step back
542 s.auth = auth
543 r = s.get(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 544–550why, one step back
544 assert r.status_code == 200
545546 @pytest.mark.parametrize(547 "username, password",548 (549 ("user", "pass"),550 ("имя".encode(), "пароль".encode()),

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 551–552why, one step back
551 (42, 42),
552 (None, None),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 553–554why, one step back
553 ),
554 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 555–556why, one step back
555 def test_set_basicauth(self, httpbin, username, password):
556 auth = (username, password)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 557–563why, one step back
557 url = httpbin("get")
558559 r = requests.Request("GET", url, auth=auth)560 p = r.prepare()561562 assert p.headers["Authorization"] == _basic_auth_str(username, password)563

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 564–566why, one step back
564 def test_basicauth_encodes_byte_strings(self):
565 """Ensure b'test' formats as the byte string "test" rather566 than the unicode string "b'test'" in Python 3.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 567–576why, one step back
567 """
568 auth = (b"\xc5\xafsername", b"test\xc6\xb6")569 r = requests.Request("GET", "http://localhost", auth=auth)570 p = r.prepare()571572 assert p.headers["Authorization"] == "Basic xa9zZXJuYW1lOnRlc3TGtg=="573574 @pytest.mark.parametrize(575 "url, exception",576 (

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 577why, one step back
577 # Connecting to an unknown domain should raise a ConnectionError

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 578why, one step back
578 ("http://doesnotexist.google.com", ConnectionError),

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 579why, one step back
579 # Connecting to an invalid port should raise a ConnectionError

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 580why, one step back
580 ("http://localhost:1", ConnectionError),

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 581why, one step back
581 # Inputing a URL that cannot be parsed should raise an InvalidURL error

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 582–584why, one step back
582 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),
583 ),584 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 585why, one step back
585 def test_errors(self, url, exception):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 586why, one step back
586 with pytest.raises(exception):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 587why, one step back
587 requests.get(url, timeout=1)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 588why, one step back
588

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 589–591why, one step back
589 def test_proxy_error(self):
590 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError591 with pytest.raises(ProxyError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 592–595why, one step back
592 requests.get(
593 "http://localhost:1", proxies={"http": "non-resolvable-address"}594 )595

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 596why, one step back
596 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 597–608why, one step back
597 with pytest.raises(InvalidProxyURL):
598 requests.get(httpbin_secure(), proxies={"https": "http:/badproxyurl:3128"})599600 with pytest.raises(InvalidProxyURL):601 requests.get(httpbin(), proxies={"http": "http://:8080"})602603 with pytest.raises(InvalidProxyURL):604 requests.get(httpbin_secure(), proxies={"https": "https://"})605606 with pytest.raises(InvalidProxyURL):607 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})608

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 609why, one step back
609 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 610–615why, one step back
610 with override_environ(http_proxy=INVALID_PROXY):
611 with pytest.raises(ProxyError):612 session = requests.Session()613 request = requests.Request("GET", httpbin())614 session.send(request.prepare())615

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 616why, one step back
616 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 617–620why, one step back
617 with override_environ(http_proxy=INVALID_PROXY):
618 with pytest.raises(ProxyError):619 session = requests.Session()620 request = requests.Request("GET", httpbin())

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 621–622why, one step back
621 prepared = session.prepare_request(request)
622 session.send(prepared)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 623why, one step back
623

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 624why, one step back
624 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 625–628why, one step back
625 with override_environ(http_proxy=INVALID_PROXY):
626 with pytest.raises(ProxyError):627 session = requests.Session()628 url = httpbin("redirect/1")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 629why, one step back
629 print(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 630–632why, one step back
630 request = requests.Request("GET", url)
631 session.send(request.prepare())632

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 633why, one step back
633 def test_respect_proxy_env_on_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 634–636why, one step back
634 with override_environ(http_proxy=INVALID_PROXY):
635 with pytest.raises(ProxyError):636 session = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 637why, one step back
637 session.get(httpbin())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 638why, one step back
638

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 639why, one step back
639 def test_respect_proxy_env_on_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 640–644why, one step back
640 with override_environ(http_proxy=INVALID_PROXY):
641 with pytest.raises(ProxyError):642 session = requests.Session()643 session.request(method="GET", url=httpbin())644

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 645–646why, one step back
645 def test_proxy_authorization_preserved_on_request(self, httpbin):
646 proxy_auth_value = "Bearer XXX"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 647why, one step back
647 session = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 648why, one step back
648 session.headers.update({"Proxy-Authorization": proxy_auth_value})

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 649–651why, one step back
649 resp = session.request(method="GET", url=httpbin("get"))
650 sent_headers = resp.json().get("headers", {})651

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 652why, one step back
652 assert sent_headers.get("Proxy-Authorization") == proxy_auth_value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 653why, one step back
653

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 654–656why, one step back
654 @pytest.mark.parametrize(
655 "url,has_proxy_auth",656 (

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 657–658why, one step back
657 ("http://example.com", True),
658 ("https://example.com", False),

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 659–660why, one step back
659 ),
660 )

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 661–663why, one step back
661 def test_proxy_authorization_not_appended_to_https_request(
662 self, url, has_proxy_auth663 ):

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 664–665why, one step back
664 session = requests.Session()
665 proxies = {

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 666–667why, one step back
666 "http": "http://test:pass@localhost:8080",
667 "https": "http://test:pass@localhost:8090",

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 668why, one step back
668 }

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 669why, one step back
669 req = requests.Request("GET", url)

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 670–672why, one step back
670 prep = req.prepare()
671 session.rebuild_proxies(prep, proxies)672

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 673why, one step back
673 assert ("Proxy-Authorization" in prep.headers) is has_proxy_auth

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 674why, one step back
674

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 675why, one step back
675 def test_basicauth_with_netrc(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 676–679why, one step back
676 auth = ("user", "pass")
677 wrong_auth = ("wronguser", "wrongpass")678 url = httpbin("basic-auth", "user", "pass")679

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 680why, one step back
680 old_auth = requests.sessions.get_netrc_auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 681–683why, one step back
681
682 try:683

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 684–685why, one step back
684 def get_netrc_auth_mock(url):
685 return auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 686why, one step back
686

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 687why, one step back
687 requests.sessions.get_netrc_auth = get_netrc_auth_mock

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 688–693why, one step back
688
689 # Should use netrc and work.690 r = requests.get(url)691 assert r.status_code == 200692693 # Given auth should override and fail.

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 694why, one step back
694 r = requests.get(url, auth=wrong_auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 695–703why, one step back
695 assert r.status_code == 401
696697 s = requests.session()698699 # Should use netrc and work.700 r = s.get(url)701 assert r.status_code == 200702703 # Given auth should override and fail.

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 704why, one step back
704 s.auth = wrong_auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 705–706why, one step back
705 r = s.get(url)
706 assert r.status_code == 401

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 707–708why, one step back
707 finally:
708 requests.sessions.get_netrc_auth = old_auth

Add new test to check netrc auth leak (#6962)danigmbefore adoption7bc4587

lines 709–738why, one step back
709
710 def test_basicauth_with_netrc_leak(self, httpbin):711 url1 = httpbin("basic-auth", "user", "pass")712 url = url1[len("http://") :]713 domain = url.split(":")[0]714 url = f"http://example.com:@{url}"715716 netrc_file = ""717 with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp:718 fp.write("machine example.com\n")719 fp.write("login wronguser\n")720 fp.write("password wrongpass\n")721 fp.write(f"machine {domain}\n")722 fp.write("login user\n")723 fp.write("password pass\n")724 fp.close()725 netrc_file = fp.name726727 old_netrc = os.environ.get("NETRC", "")728 os.environ["NETRC"] = netrc_file729730 try:731 # Should use netrc732 # Make sure that we don't use the example.com credentails733 # for the request734 r = requests.get(url)735 assert r.status_code == 200736 finally:737 os.environ["NETRC"] = old_netrc738 os.unlink(netrc_file)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 739why, one step back
739

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 740why, one step back
740 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 741–756why, one step back
741 for authtype in self.digest_auth_algo:
742 auth = HTTPDigestAuth("user", "pass")743 url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")744745 r = requests.get(url, auth=auth)746 assert r.status_code == 200747748 r = requests.get(url)749 assert r.status_code == 401750 print(r.headers["WWW-Authenticate"])751752 s = requests.session()753 s.auth = HTTPDigestAuth("user", "pass")754 r = s.get(url)755 assert r.status_code == 200756

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 757why, one step back
757 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 758–766why, one step back
758 for authtype in self.digest_auth_algo:
759 url = httpbin("digest-auth", "auth", "user", "pass", authtype)760 auth = HTTPDigestAuth("user", "pass")761 r = requests.get(url)762 assert r.cookies["fake"] == "fake_value"763764 r = requests.get(url, auth=auth)765 assert r.status_code == 200766

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 767why, one step back
767 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 768–770why, one step back
768 for authtype in self.digest_auth_algo:
769 url = httpbin("digest-auth", "auth", "user", "pass", authtype)770 auth = HTTPDigestAuth("user", "pass")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 771–772why, one step back
771 s = requests.Session()
772 s.get(url, auth=auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 773–774why, one step back
773 assert s.cookies["fake"] == "fake_value"
774

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 775why, one step back
775 def test_DIGEST_STREAM(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 776–779why, one step back
776 for authtype in self.digest_auth_algo:
777 auth = HTTPDigestAuth("user", "pass")778 url = httpbin("digest-auth", "auth", "user", "pass", authtype)779

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 780why, one step back
780 r = requests.get(url, auth=auth, stream=True)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 781–782why, one step back
781 assert r.raw.read() != b""
782

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 783why, one step back
783 r = requests.get(url, auth=auth, stream=False)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 784–785why, one step back
784 assert r.raw.read() == b""
785

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 786why, one step back
786 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 787–797why, one step back
787 for authtype in self.digest_auth_algo:
788 auth = HTTPDigestAuth("user", "wrongpass")789 url = httpbin("digest-auth", "auth", "user", "pass", authtype)790791 r = requests.get(url, auth=auth)792 assert r.status_code == 401793794 r = requests.get(url)795 assert r.status_code == 401796797 s = requests.session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 798why, one step back
798 s.auth = auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 799–801why, one step back
799 r = s.get(url)
800 assert r.status_code == 401801

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 802why, one step back
802 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 803–809why, one step back
803 for authtype in self.digest_auth_algo:
804 auth = HTTPDigestAuth("user", "pass")805 url = httpbin("digest-auth", "auth", "user", "pass", authtype)806807 r = requests.get(url, auth=auth)808 assert '"auth"' in r.request.headers["Authorization"]809

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 810why, one step back
810 def test_POSTBIN_GET_POST_FILES(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 811–826why, one step back
811 url = httpbin("post")
812 requests.post(url).raise_for_status()813814 post1 = requests.post(url, data={"some": "data"})815 assert post1.status_code == 200816817 with open("requirements-dev.txt") as f:818 post2 = requests.post(url, files={"some": f})819 assert post2.status_code == 200820821 post4 = requests.post(url, data='[{"some": "json"}]')822 assert post4.status_code == 200823824 with pytest.raises(ValueError):825 requests.post(url, files=["bad file data"])826

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 827why, one step back
827 def test_invalid_files_input(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 828–829why, one step back
828 url = httpbin("post")
829 post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 830–831why, one step back
830 assert b'name="random-file-1"' not in post.request.body
831 assert b'name="random-file-2"' in post.request.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 832why, one step back
832

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 833why, one step back
833 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 834–835why, one step back
834 class TestStream:
835 def __init__(self, data):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 836–838why, one step back
836 self.data = data.encode()
837 self.length = len(self.data)838 self.index = 0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 839–840why, one step back
839
840 def __len__(self):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 841why, one step back
841 return self.length

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 842why, one step back
842

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 843–844why, one step back
843 def read(self, size=None):
844 if size:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 845why, one step back
845 ret = self.data[self.index : self.index + size]

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 846–847why, one step back
846 self.index += size
847 else:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 848why, one step back
848 ret = self.data[self.index :]

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 849–850why, one step back
849 self.index = self.length
850 return ret

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 851–852why, one step back
851
852 def tell(self):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 853why, one step back
853 return self.index

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 854why, one step back
854

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 855–861why, one step back
855 def seek(self, offset, where=0):
856 if where == 0:857 self.index = offset858 elif where == 1:859 self.index += offset860 elif where == 2:861 self.index = self.length + offset

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 862–868why, one step back
862
863 test = TestStream("test")864 post1 = requests.post(httpbin("post"), data=test)865 assert post1.status_code == 200866 assert post1.json()["data"] == "test"867868 test = TestStream("test")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 869why, one step back
869 test.seek(2)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 870–873why, one step back
870 post2 = requests.post(httpbin("post"), data=test)
871 assert post2.status_code == 200872 assert post2.json()["data"] == "st"873

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 874why, one step back
874 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 875–890why, one step back
875 url = httpbin("post")
876 requests.post(url).raise_for_status()877878 post1 = requests.post(url, data={"some": "data"})879 assert post1.status_code == 200880881 with open("requirements-dev.txt") as f:882 post2 = requests.post(url, data={"some": "data"}, files={"some": f})883 assert post2.status_code == 200884885 post4 = requests.post(url, data='[{"some": "json"}]')886 assert post4.status_code == 200887888 with pytest.raises(ValueError):889 requests.post(url, files=["bad file data"])890

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 891–894why, one step back
891 def test_post_with_custom_mapping(self, httpbin):
892 class CustomMapping(MutableMapping):893 def __init__(self, *args, **kwargs):894 self.data = dict(*args, **kwargs)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 895why, one step back
895

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 896–897why, one step back
896 def __delitem__(self, key):
897 del self.data[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 898why, one step back
898

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 899–900why, one step back
899 def __getitem__(self, key):
900 return self.data[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 901why, one step back
901

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 902–903why, one step back
902 def __setitem__(self, key, value):
903 self.data[key] = value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 904–905why, one step back
904
905 def __iter__(self):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 906why, one step back
906 return iter(self.data)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 907–908why, one step back
907
908 def __len__(self):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 909why, one step back
909 return len(self.data)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 910–915why, one step back
910
911 data = CustomMapping({"some": "data"})912 url = httpbin("post")913 found_json = requests.post(url, data=data).json().get("form")914 assert found_json == {"some": "data"}915

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 916why, one step back
916 def test_conflicting_post_params(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 917–918why, one step back
917 url = httpbin("post")
918 with open("requirements-dev.txt") as f:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 919why, one step back
919 with pytest.raises(ValueError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 920–921why, one step back
920 requests.post(url, data='[{"some": "data"}]', files={"some": f})
921

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 922why, one step back
922 def test_request_ok_set(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 923–925why, one step back
923 r = requests.get(httpbin("status", "404"))
924 assert not r.ok925

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 926why, one step back
926 def test_status_raising(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 927why, one step back
927 r = requests.get(httpbin("status", "404"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 928why, one step back
928 with pytest.raises(requests.exceptions.HTTPError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 929–933why, one step back
929 r.raise_for_status()
930931 r = requests.get(httpbin("status", "500"))932 assert not r.ok933

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 934why, one step back
934 def test_decompress_gzip(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 935–947why, one step back
935 r = requests.get(httpbin("gzip"))
936 r.content.decode("ascii")937938 @pytest.mark.parametrize(939 "url, params",940 (941 ("/get", {"foo": "føø"}),942 ("/get", {"føø": "føø"}),943 ("/get", {"føø": "føø"}),944 ("/get", {"foo": "foo"}),945 ("ø", {"foo": "foo"}),946 ),947 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 948–949why, one step back
948 def test_unicode_get(self, httpbin, url, params):
949 requests.get(httpbin(url), params=params)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 950why, one step back
950

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 951–952why, one step back
951 def test_unicode_header_name(self, httpbin):
952 requests.put(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 953–957why, one step back
953 httpbin("put"),
954 headers={"Content-Type": "application/octet-stream"},955 data="\xff",956 ) # compat.str is unicode.957

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 958why, one step back
958 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 959–960why, one step back
959 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)
960

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 961why, one step back
961 def test_invalid_ca_certificate_path(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 962–963why, one step back
962 INVALID_PATH = "/garbage"
963 with pytest.raises(IOError) as e:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 964why, one step back
964 requests.get(httpbin_secure(), verify=INVALID_PATH)

Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f

lines 965–967why, one step back
965 assert (
966 str(e.value)967 == f"Could not find a suitable TLS CA certificate bundle, invalid path: {INVALID_PATH}"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 968–969why, one step back
968 )
969

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 970why, one step back
970 def test_invalid_ssl_certificate_files(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 971–972why, one step back
971 INVALID_PATH = "/garbage"
972 with pytest.raises(IOError) as e:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 973why, one step back
973 requests.get(httpbin_secure(), cert=INVALID_PATH)

Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f

lines 974–976why, one step back
974 assert (
975 str(e.value)976 == f"Could not find the TLS certificate file, invalid path: {INVALID_PATH}"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 977–987why, one step back
977 )
978979 with pytest.raises(IOError) as e:980 requests.get(httpbin_secure(), cert=(".", INVALID_PATH))981 assert str(e.value) == (982 f"Could not find the TLS key file, invalid path: {INVALID_PATH}"983 )984985 @pytest.mark.parametrize(986 "env, expected",987 (

Merge pull request #6074 from nateprewitt/curl_ca_bundleIan Stapleton Cordascobefore adoption79f6027

line 988why, one step back
988 ({}, True),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 989–1009why, one step back
989 ({"REQUESTS_CA_BUNDLE": "/some/path"}, "/some/path"),
990 ({"REQUESTS_CA_BUNDLE": ""}, True),991 ({"CURL_CA_BUNDLE": "/some/path"}, "/some/path"),992 ({"CURL_CA_BUNDLE": ""}, True),993 ({"REQUESTS_CA_BUNDLE": "", "CURL_CA_BUNDLE": ""}, True),994 (995 {996 "REQUESTS_CA_BUNDLE": "/some/path",997 "CURL_CA_BUNDLE": "/curl/path",998 },999 "/some/path",1000 ),1001 (1002 {1003 "REQUESTS_CA_BUNDLE": "",1004 "CURL_CA_BUNDLE": "/curl/path",1005 },1006 "/curl/path",1007 ),1008 ),1009 )

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 1010why, one step back
1010 def test_env_cert_bundles(self, httpbin, env, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1011why, one step back
1011 s = requests.Session()

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

lines 1012–1015why, one step back
1012 with mock.patch("os.environ", env):
1013 settings = s.merge_environment_settings(1014 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None1015 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1016–1017why, one step back
1016 assert settings["verify"] == expected
1017

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1018why, one step back
1018 def test_http_with_certificate(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1019–1021why, one step back
1019 r = requests.get(httpbin(), cert=".")
1020 assert r.status_code == 2001021

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

lines 1022–1025why, one step back
1022 @pytest.mark.skipif(
1023 SNIMissingWarning is None,1024 reason="urllib3 2.0 removed that warning and errors out instead",1025 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1026–1029why, one step back
1026 def test_https_warnings(self, nosan_server):
1027 """warnings are emitted with requests.get"""1028 host, port, ca_bundle = nosan_server1029 if HAS_MODERN_SSL or HAS_PYOPENSSL:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1030–1037why, one step back
1030 warnings_expected = ("SubjectAltNameWarning",)
1031 else:1032 warnings_expected = (1033 "SNIMissingWarning",1034 "InsecurePlatformWarning",1035 "SubjectAltNameWarning",1036 )1037

Merge pull request #6682 from frenzymadness/pytest8Ian Stapleton Cordascobefore adoption31ebb81

line 1038why, one step back
1038 with pytest.warns() as warning_records:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1039–1048why, one step back
1039 warnings.simplefilter("always")
1040 requests.get(f"https://localhost:{port}/", verify=ca_bundle)10411042 warning_records = [1043 item1044 for item in warning_records1045 if item.category.__name__ != "ResourceWarning"1046 ]10471048 warnings_category = tuple(item.category.__name__ for item in warning_records)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1049why, one step back
1049 assert warnings_category == warnings_expected

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1050why, one step back
1050

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1051why, one step back
1051 def test_certificate_failure(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1052why, one step back
1052 """

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1053why, one step back
1053 When underlying SSL problems occur, an SSLError is raised.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1054why, one step back
1054 """

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1055why, one step back
1055 with pytest.raises(RequestsSSLError):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1056–1057why, one step back
1056 # Our local httpbin does not have a trusted CA, so this call will
1057 # fail if we use our default trust bundle.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1058–1059why, one step back
1058 requests.get(httpbin_secure("status", "200"))
1059

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1060why, one step back
1060 def test_urlencoded_get_query_multivalued_param(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1061–1064why, one step back
1061 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
1062 assert r.status_code == 2001063 assert r.url == httpbin("get?test=foo&test=baz")1064

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1065why, one step back
1065 def test_form_encoded_post_query_multivalued_element(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1066–1071why, one step back
1066 r = requests.Request(
1067 method="POST", url=httpbin("post"), data=dict(test=["foo", "baz"])1068 )1069 prep = r.prepare()1070 assert prep.body == "test=foo&test=baz"1071

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1072why, one step back
1072 def test_different_encodings_dont_break_post(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1073–1079why, one step back
1073 with open(__file__, "rb") as f:
1074 r = requests.post(1075 httpbin("post"),1076 data={"stuff": json.dumps({"a": 123})},1077 params={"blah": "asdf1234"},1078 files={"file": ("test_requests.py", f)},1079 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1080–1090why, one step back
1080 assert r.status_code == 200
10811082 @pytest.mark.parametrize(1083 "data",1084 (1085 {"stuff": "ëlïxr"},1086 {"stuff": "ëlïxr".encode()},1087 {"stuff": "elixr"},1088 {"stuff": b"elixr"},1089 ),1090 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1091why, one step back
1091 def test_unicode_multipart_post(self, httpbin, data):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1092–1097why, one step back
1092 with open(__file__, "rb") as f:
1093 r = requests.post(1094 httpbin("post"),1095 data=data,1096 files={"file": ("test_requests.py", f)},1097 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1098–1099why, one step back
1098 assert r.status_code == 200
1099

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1100why, one step back
1100 def test_unicode_multipart_post_fieldnames(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1101why, one step back
1101 filename = os.path.splitext(__file__)[0] + ".py"

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1102–1110why, one step back
1102 with open(filename, "rb") as f:
1103 r = requests.Request(1104 method="POST",1105 url=httpbin("post"),1106 data={b"stuff": "elixr"},1107 files={"file": ("test_requests.py", f)},1108 )1109 prep = r.prepare()1110

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1111why, one step back
1111 assert b'name="stuff"' in prep.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1112–1113why, one step back
1112 assert b"name=\"b'stuff'\"" not in prep.body
1113

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1114why, one step back
1114 def test_unicode_method_name(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1115–1121why, one step back
1115 with open(__file__, "rb") as f:
1116 files = {"file": f}1117 r = requests.request(1118 method="POST",1119 url=httpbin("post"),1120 files=files,1121 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1122–1123why, one step back
1122 assert r.status_code == 200
1123

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1124why, one step back
1124 def test_unicode_method_name_with_request_object(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1125why, one step back
1125 s = requests.Session()

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1126–1129why, one step back
1126 with open(__file__, "rb") as f:
1127 files = {"file": f}1128 req = requests.Request("POST", httpbin("post"), files=files)1129 prep = s.prepare_request(req)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1130why, one step back
1130 assert isinstance(prep.method, builtin_str)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1131–1135why, one step back
1131 assert prep.method == "POST"
11321133 resp = s.send(prep)1134 assert resp.status_code == 2001135

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1136why, one step back
1136 def test_non_prepared_request_error(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1137–1140why, one step back
1137 s = requests.Session()
1138 req = requests.Request("POST", "/")11391140 with pytest.raises(ValueError) as e:

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1141why, one step back
1141 s.send(req)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1142–1143why, one step back
1142 assert str(e.value) == "You can only send PreparedRequests."
1143

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1144why, one step back
1144 def test_custom_content_type(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1145–1146why, one step back
1145 with open(__file__, "rb") as f1:
1146 with open(__file__, "rb") as f2:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1147why, one step back
1147 data = {"stuff": json.dumps({"a": 123})}

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1148–1152why, one step back
1148 files = {
1149 "file1": ("test_requests.py", f1),1150 "file2": ("test_requests", f2, "text/py-content-type"),1151 }1152 r = requests.post(httpbin("post"), data=data, files=files)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1153why, one step back
1153 assert r.status_code == 200

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1154why, one step back
1154 assert b"text/py-content-type" in r.request.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1155why, one step back
1155

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1156why, one step back
1156 def test_hook_receives_request_arguments(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1157why, one step back
1157 def hook(resp, **kwargs):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1158–1159why, one step back
1158 assert resp is not None
1159 assert kwargs != {}

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1160–1163why, one step back
1160
1161 s = requests.Session()1162 r = requests.Request("GET", httpbin(), hooks={"response": hook})1163 prep = s.prepare_request(r)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1164why, one step back
1164 s.send(prep)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1165why, one step back
1165

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1166why, one step back
1166 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1167–1176why, one step back
1167 def hook(*args, **kwargs):
1168 pass11691170 s = requests.Session()1171 s.hooks["response"].append(hook)1172 r = requests.Request("GET", httpbin())1173 prep = s.prepare_request(r)1174 assert prep.hooks["response"] != []1175 assert prep.hooks["response"] == [hook]1176

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1177why, one step back
1177 def test_session_hooks_are_overridden_by_request_hooks(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1178–1183why, one step back
1178 def hook1(*args, **kwargs):
1179 pass11801181 def hook2(*args, **kwargs):1182 pass1183

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1184why, one step back
1184 assert hook1 is not hook2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1185–1190why, one step back
1185 s = requests.Session()
1186 s.hooks["response"].append(hook2)1187 r = requests.Request("GET", httpbin(), hooks={"response": [hook1]})1188 prep = s.prepare_request(r)1189 assert prep.hooks["response"] == [hook1]1190

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1191why, one step back
1191 def test_prepared_request_hook(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1192why, one step back
1192 def hook(resp, **kwargs):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1193why, one step back
1193 resp.hook_working = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1194–1196why, one step back
1194 return resp
11951196 req = requests.Request("GET", httpbin(), hooks={"response": hook})

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1197why, one step back
1197 prep = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1198–1204why, one step back
1198
1199 s = requests.Session()1200 s.proxies = getproxies()1201 resp = s.send(prep)12021203 assert hasattr(resp, "hook_working")1204

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1205–1207why, one step back
1205 def test_prepared_from_session(self, httpbin):
1206 class DummyAuth(requests.auth.AuthBase):1207 def __call__(self, r):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1208why, one step back
1208 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1209why, one step back
1209 return r

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1210–1211why, one step back
1210
1211 req = requests.Request("GET", httpbin("headers"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1212why, one step back
1212 assert not req.auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1213–1214why, one step back
1213
1214 s = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1215why, one step back
1215 s.auth = DummyAuth()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1216–1221why, one step back
1216
1217 prep = s.prepare_request(req)1218 resp = s.send(prep)12191220 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1221

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1222why, one step back
1222 def test_prepare_request_with_bytestring_url(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1223–1225why, one step back
1223 req = requests.Request("GET", b"https://httpbin.org/")
1224 s = requests.Session()1225 prep = s.prepare_request(req)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1226why, one step back
1226 assert prep.url == "https://httpbin.org/"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1227why, one step back
1227

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1228why, one step back
1228 def test_request_with_bytestring_host(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1229why, one step back
1229 s = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1230why, one step back
1230 resp = s.request(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1231–1232why, one step back
1231 "GET",
1232 httpbin("cookies/set?cookie=value"),

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1233why, one step back
1233 allow_redirects=False,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1234–1237why, one step back
1234 headers={"Host": b"httpbin.org"},
1235 )1236 assert resp.cookies.get("cookie") == "value"1237

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1238why, one step back
1238 def test_links(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1239why, one step back
1239 r = requests.Response()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1240why, one step back
1240 r.headers = {

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1241–1263why, one step back
1241 "cache-control": "public, max-age=60, s-maxage=60",
1242 "connection": "keep-alive",1243 "content-encoding": "gzip",1244 "content-type": "application/json; charset=utf-8",1245 "date": "Sat, 26 Jan 2013 16:47:56 GMT",1246 "etag": '"6ff6a73c0e446c1f61614769e3ceb778"',1247 "last-modified": "Sat, 26 Jan 2013 16:22:39 GMT",1248 "link": (1249 "<https://api.github.com/users/kennethreitz/repos?"1250 'page=2&per_page=10>; rel="next", <https://api.github.'1251 "com/users/kennethreitz/repos?page=7&per_page=10>; "1252 ' rel="last"'1253 ),1254 "server": "GitHub.com",1255 "status": "200 OK",1256 "vary": "Accept",1257 "x-content-type-options": "nosniff",1258 "x-github-media-type": "github.beta",1259 "x-ratelimit-limit": "60",1260 "x-ratelimit-remaining": "57",1261 }1262 assert r.links["next"]["rel"] == "next"1263

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1264why, one step back
1264 def test_cookie_parameters(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1265–1266why, one step back
1265 key = "some_cookie"
1266 value = "some_value"

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1267why, one step back
1267 secure = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1268–1271why, one step back
1268 domain = "test.com"
1269 rest = {"HttpOnly": True}12701271 jar = requests.cookies.RequestsCookieJar()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1272why, one step back
1272 jar.set(key, value, secure=secure, domain=domain, rest=rest)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1273why, one step back
1273

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1274why, one step back
1274 assert len(jar) == 1

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1275–1276why, one step back
1275 assert "some_cookie" in jar
1276

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1277–1279why, one step back
1277 cookie = list(jar)[0]
1278 assert cookie.secure == secure1279 assert cookie.domain == domain

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1280–1281why, one step back
1280 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]
1281

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1282why, one step back
1282 def test_cookie_as_dict_keeps_len(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1283–1296why, one step back
1283 key = "some_cookie"
1284 value = "some_value"12851286 key1 = "some_cookie1"1287 value1 = "some_value1"12881289 jar = requests.cookies.RequestsCookieJar()1290 jar.set(key, value)1291 jar.set(key1, value1)12921293 d1 = dict(jar)1294 d2 = dict(jar.iteritems())1295 d3 = dict(jar.items())1296

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1297–1300why, one step back
1297 assert len(jar) == 2
1298 assert len(d1) == 21299 assert len(d2) == 21300 assert len(d3) == 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1301why, one step back
1301

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1302why, one step back
1302 def test_cookie_as_dict_keeps_items(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1303–1320why, one step back
1303 key = "some_cookie"
1304 value = "some_value"13051306 key1 = "some_cookie1"1307 value1 = "some_value1"13081309 jar = requests.cookies.RequestsCookieJar()1310 jar.set(key, value)1311 jar.set(key1, value1)13121313 d1 = dict(jar)1314 d2 = dict(jar.iteritems())1315 d3 = dict(jar.items())13161317 assert d1["some_cookie"] == "some_value"1318 assert d2["some_cookie"] == "some_value"1319 assert d3["some_cookie1"] == "some_value1"1320

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1321why, one step back
1321 def test_cookie_as_dict_keys(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1322–1331why, one step back
1322 key = "some_cookie"
1323 value = "some_value"13241325 key1 = "some_cookie1"1326 value1 = "some_value1"13271328 jar = requests.cookies.RequestsCookieJar()1329 jar.set(key, value)1330 jar.set(key1, value1)1331

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1332–1335why, one step back
1332 keys = jar.keys()
1333 assert keys == list(keys)1334 # make sure one can use keys multiple times1335 assert list(keys) == list(keys)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1336why, one step back
1336

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1337why, one step back
1337 def test_cookie_as_dict_values(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1338–1347why, one step back
1338 key = "some_cookie"
1339 value = "some_value"13401341 key1 = "some_cookie1"1342 value1 = "some_value1"13431344 jar = requests.cookies.RequestsCookieJar()1345 jar.set(key, value)1346 jar.set(key1, value1)1347

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1348–1351why, one step back
1348 values = jar.values()
1349 assert values == list(values)1350 # make sure one can use values multiple times1351 assert list(values) == list(values)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1352why, one step back
1352

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1353why, one step back
1353 def test_cookie_as_dict_items(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1354–1364why, one step back
1354 key = "some_cookie"
1355 value = "some_value"13561357 key1 = "some_cookie1"1358 value1 = "some_value1"13591360 jar = requests.cookies.RequestsCookieJar()1361 jar.set(key, value)1362 jar.set(key1, value1)13631364 items = jar.items()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1365–1367why, one step back
1365 assert items == list(items)
1366 # make sure one can use items multiple times1367 assert list(items) == list(items)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1368why, one step back
1368

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1369why, one step back
1369 def test_cookie_duplicate_names_different_domains(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1370–1375why, one step back
1370 key = "some_cookie"
1371 value = "some_value"1372 domain1 = "test1.com"1373 domain2 = "test2.com"13741375 jar = requests.cookies.RequestsCookieJar()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1376–1378why, one step back
1376 jar.set(key, value, domain=domain1)
1377 jar.set(key, value, domain=domain2)1378 assert key in jar

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1379why, one step back
1379 items = jar.items()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1380why, one step back
1380 assert len(items) == 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1381why, one step back
1381

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1382why, one step back
1382 # Verify that CookieConflictError is raised if domain is not specified

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1383–1385why, one step back
1383 with pytest.raises(requests.cookies.CookieConflictError):
1384 jar.get(key)1385

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1386–1388why, one step back
1386 # Verify that CookieConflictError is not raised if domain is specified
1387 cookie = jar.get(key, domain=domain1)1388 assert cookie == value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1389why, one step back
1389

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1390why, one step back
1390 def test_cookie_duplicate_names_raises_cookie_conflict_error(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1391–1395why, one step back
1391 key = "some_cookie"
1392 value = "some_value"1393 path = "some_path"13941395 jar = requests.cookies.RequestsCookieJar()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1396why, one step back
1396 jar.set(key, value, path=path)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1397–1400why, one step back
1397 jar.set(key, value)
1398 with pytest.raises(requests.cookies.CookieConflictError):1399 jar.get(key)1400

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1401–1402why, one step back
1401 def test_cookie_policy_copy(self):
1402 class MyCookiePolicy(cookielib.DefaultCookiePolicy):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1403–1405why, one step back
1403 pass
14041405 jar = requests.cookies.RequestsCookieJar()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1406–1407why, one step back
1406 jar.set_policy(MyCookiePolicy())
1407 assert isinstance(jar.copy().get_policy(), MyCookiePolicy)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1408why, one step back
1408

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1409why, one step back
1409 def test_time_elapsed_blank(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1410why, one step back
1410 r = requests.get(httpbin("get"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1411why, one step back
1411 td = r.elapsed

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1412–1414why, one step back
1412 total_seconds = (
1413 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61414 ) / 10**6

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1415why, one step back
1415 assert total_seconds > 0.0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1416why, one step back
1416

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1417why, one step back
1417 def test_empty_response_has_content_none(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1418–1420why, one step back
1418 r = requests.Response()
1419 assert r.content is None1420

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1421why, one step back
1421 def test_response_is_iterable(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1422–1423why, one step back
1422 r = requests.Response()
1423 io = StringIO.StringIO("abc")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1424why, one step back
1424 read_ = io.read

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1425why, one step back
1425

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1426–1427why, one step back
1426 def read_mock(amt, decode_content=None):
1427 return read_(amt)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1428–1429why, one step back
1428
1429 setattr(io, "read", read_mock)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1430–1432why, one step back
1430 r.raw = io
1431 assert next(iter(r))1432 io.close()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1433why, one step back
1433

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1434–1436why, one step back
1434 def test_response_decode_unicode(self):
1435 """When called with decode_unicode, Response.iter_content should always1436 return unicode.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1437–1438why, one step back
1437 """
1438 r = requests.Response()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1439why, one step back
1439 r._content_consumed = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1440–1445why, one step back
1440 r._content = b"the content"
1441 r.encoding = "ascii"14421443 chunks = r.iter_content(decode_unicode=True)1444 assert all(isinstance(chunk, str) for chunk in chunks)1445

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1446why, one step back
1446 # also for streaming

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1447–1452why, one step back
1447 r = requests.Response()
1448 r.raw = io.BytesIO(b"the content")1449 r.encoding = "ascii"1450 chunks = r.iter_content(decode_unicode=True)1451 assert all(isinstance(chunk, str) for chunk in chunks)1452

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1453–1454why, one step back
1453 def test_response_reason_unicode(self):
1454 # check for unicode HTTP status

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1455–1457why, one step back
1455 r = requests.Response()
1456 r.url = "unicode URL"1457 r.reason = "Komponenttia ei löydy".encode()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1458why, one step back
1458 r.status_code = 404

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1459why, one step back
1459 r.encoding = None

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1460why, one step back
1460 assert not r.ok # old behaviour - crashes here

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1461why, one step back
1461

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1462–1463why, one step back
1462 def test_response_reason_unicode_fallback(self):
1463 # check raise_status falls back to ISO-8859-1

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1464–1467why, one step back
1464 r = requests.Response()
1465 r.url = "some url"1466 reason = "Komponenttia ei löydy"1467 r.reason = reason.encode("latin-1")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1468why, one step back
1468 r.status_code = 500

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1469why, one step back
1469 r.encoding = None

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1470why, one step back
1470 with pytest.raises(requests.exceptions.HTTPError) as e:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1471why, one step back
1471 r.raise_for_status()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1472why, one step back
1472 assert reason in e.value.args[0]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1473why, one step back
1473

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1474–1476why, one step back
1474 def test_response_chunk_size_type(self):
1475 """Ensure that chunk_size is passed as None or an integer, otherwise1476 raise a TypeError.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1477–1479why, one step back
1477 """
1478 r = requests.Response()1479 r.raw = io.BytesIO(b"the content")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1480–1481why, one step back
1480 chunks = r.iter_content(1)
1481 assert all(len(chunk) == 1 for chunk in chunks)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1482–1484why, one step back
1482
1483 r = requests.Response()1484 r.raw = io.BytesIO(b"the content")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1485why, one step back
1485 chunks = r.iter_content(None)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1486–1490why, one step back
1486 assert list(chunks) == [b"the content"]
14871488 r = requests.Response()1489 r.raw = io.BytesIO(b"the content")1490 with pytest.raises(TypeError):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1491why, one step back
1491 chunks = r.iter_content("1024")

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1492–1495why, one step back
1492
1493 @pytest.mark.parametrize(1494 "exception, args, expected",1495 (

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1496–1497why, one step back
1496 (urllib3.exceptions.ProtocolError, tuple(), ChunkedEncodingError),
1497 (urllib3.exceptions.DecodeError, tuple(), ContentDecodingError),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1498why, one step back
1498 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1499why, one step back
1499 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1500–1501why, one step back
1500 ),
1501 )

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 1502why, one step back
1502 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1503why, one step back
1503 r = requests.Response()

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 1504why, one step back
1504 r.raw = mock.Mock()

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1505–1507why, one step back
1505 # ReadTimeoutError can't be initialized by mock
1506 # so we'll manually create the instance with args1507 r.raw.stream.side_effect = exception(*args)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1508why, one step back
1508

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1509–1510why, one step back
1509 with pytest.raises(expected):
1510 next(r.iter_content(1024))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1511why, one step back
1511

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1512why, one step back
1512 def test_request_and_response_are_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1513–1514why, one step back
1513 r = requests.get(httpbin("get"))
1514

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1515–1516why, one step back
1515 # verify we can pickle the original request
1516 assert pickle.loads(pickle.dumps(r.request))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1517why, one step back
1517

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1518–1522why, one step back
1518 # verify we can pickle the response and that we have access to
1519 # the original request.1520 pr = pickle.loads(pickle.dumps(r))1521 assert r.request.url == pr.request.url1522 assert r.request.headers == pr.request.headers

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1523why, one step back
1523

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1524why, one step back
1524 def test_prepared_request_is_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1525–1537why, one step back
1525 p = requests.Request("GET", httpbin("get")).prepare()
15261527 # Verify PreparedRequest can be pickled and unpickled1528 r = pickle.loads(pickle.dumps(p))1529 assert r.url == p.url1530 assert r.headers == p.headers1531 assert r.body == p.body15321533 # Verify unpickled PreparedRequest sends properly1534 s = requests.Session()1535 resp = s.send(r)1536 assert resp.status_code == 2001537

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1538why, one step back
1538 def test_prepared_request_with_file_is_pickleable(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1539–1541why, one step back
1539 with open(__file__, "rb") as f:
1540 r = requests.Request("POST", httpbin("post"), files={"file": f})1541 p = r.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1542–1553why, one step back
1542
1543 # Verify PreparedRequest can be pickled and unpickled1544 r = pickle.loads(pickle.dumps(p))1545 assert r.url == p.url1546 assert r.headers == p.headers1547 assert r.body == p.body15481549 # Verify unpickled PreparedRequest sends properly1550 s = requests.Session()1551 resp = s.send(r)1552 assert resp.status_code == 2001553

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1554why, one step back
1554 def test_prepared_request_with_hook_is_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1555–1557why, one step back
1555 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())
1556 p = r.prepare()1557

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1558why, one step back
1558 # Verify PreparedRequest can be pickled

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1559–1562why, one step back
1559 r = pickle.loads(pickle.dumps(p))
1560 assert r.url == p.url1561 assert r.headers == p.headers1562 assert r.body == p.body

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1563why, one step back
1563 assert r.hooks == p.hooks

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1564–1569why, one step back
1564
1565 # Verify unpickled PreparedRequest sends properly1566 s = requests.Session()1567 resp = s.send(r)1568 assert resp.status_code == 2001569

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1570–1571why, one step back
1570 def test_cannot_send_unprepared_requests(self, httpbin):
1571 r = requests.Request(url=httpbin())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1572why, one step back
1572 with pytest.raises(ValueError):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1573why, one step back
1573 requests.Session().send(r)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1574why, one step back
1574

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1575–1579why, one step back
1575 def test_http_error(self):
1576 error = requests.exceptions.HTTPError()1577 assert not error.response1578 response = requests.Response()1579 error = requests.exceptions.HTTPError(response=response)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1580–1584why, one step back
1580 assert error.response == response
1581 error = requests.exceptions.HTTPError("message", response=response)1582 assert str(error) == "message"1583 assert error.response == response1584

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1585why, one step back
1585 def test_session_pickling(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1586–1588why, one step back
1586 r = requests.Request("GET", httpbin("get"))
1587 s = requests.Session()1588

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1589why, one step back
1589 s = pickle.loads(pickle.dumps(s))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1590–1594why, one step back
1590 s.proxies = getproxies()
15911592 r = s.send(r.prepare())1593 assert r.status_code == 2001594

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1595–1596why, one step back
1595 def test_fixes_1329(self, httpbin):
1596 """Ensure that header updates are done case-insensitively."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1597–1600why, one step back
1597 s = requests.Session()
1598 s.headers.update({"ACCEPT": "BOGUS"})1599 s.headers.update({"accept": "application/json"})1600 r = s.get(httpbin("get"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1601why, one step back
1601 headers = r.request.headers

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1602–1605why, one step back
1602 assert headers["accept"] == "application/json"
1603 assert headers["Accept"] == "application/json"1604 assert headers["ACCEPT"] == "application/json"1605

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1606why, one step back
1606 def test_uppercase_scheme_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1607why, one step back
1607 parts = urlparse(httpbin("html"))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1608why, one step back
1608 url = "HTTP://" + parts.netloc + parts.path

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1609–1610why, one step back
1609 r = requests.get(httpbin("redirect-to"), params={"url": url})
1610 assert r.status_code == 200

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1611why, one step back
1611 assert r.url.lower() == url.lower()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1612why, one step back
1612

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1613why, one step back
1613 def test_transport_adapter_ordering(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1614–1644why, one step back
1614 s = requests.Session()
1615 order = ["https://", "http://"]1616 assert order == list(s.adapters)1617 s.mount("http://git", HTTPAdapter())1618 s.mount("http://github", HTTPAdapter())1619 s.mount("http://github.com", HTTPAdapter())1620 s.mount("http://github.com/about/", HTTPAdapter())1621 order = [1622 "http://github.com/about/",1623 "http://github.com",1624 "http://github",1625 "http://git",1626 "https://",1627 "http://",1628 ]1629 assert order == list(s.adapters)1630 s.mount("http://gittip", HTTPAdapter())1631 s.mount("http://gittip.com", HTTPAdapter())1632 s.mount("http://gittip.com/about/", HTTPAdapter())1633 order = [1634 "http://github.com/about/",1635 "http://gittip.com/about/",1636 "http://github.com",1637 "http://gittip.com",1638 "http://github",1639 "http://gittip",1640 "http://git",1641 "https://",1642 "http://",1643 ]1644 assert order == list(s.adapters)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1645why, one step back
1645 s2 = requests.Session()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1646–1650why, one step back
1646 s2.adapters = {"http://": HTTPAdapter()}
1647 s2.mount("https://", HTTPAdapter())1648 assert "http://" in s2.adapters1649 assert "https://" in s2.adapters1650

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1651why, one step back
1651 def test_session_get_adapter_prefix_matching(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1652–1659why, one step back
1652 prefix = "https://example.com"
1653 more_specific_prefix = prefix + "/some/path"16541655 url_matching_only_prefix = prefix + "/another/path"1656 url_matching_more_specific_prefix = more_specific_prefix + "/longer/path"1657 url_not_matching_prefix = "https://another.example.com/"16581659 s = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1660–1663why, one step back
1660 prefix_adapter = HTTPAdapter()
1661 more_specific_prefix_adapter = HTTPAdapter()1662 s.mount(prefix, prefix_adapter)1663 s.mount(more_specific_prefix, more_specific_prefix_adapter)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1664why, one step back
1664

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1665why, one step back
1665 assert s.get_adapter(url_matching_only_prefix) is prefix_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1666–1674why, one step back
1666 assert (
1667 s.get_adapter(url_matching_more_specific_prefix)1668 is more_specific_prefix_adapter1669 )1670 assert s.get_adapter(url_not_matching_prefix) not in (1671 prefix_adapter,1672 more_specific_prefix_adapter,1673 )1674

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1675why, one step back
1675 def test_session_get_adapter_prefix_matching_mixed_case(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1676–1682why, one step back
1676 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1677 url_matching_prefix = mixed_case_prefix + "/full_url"16781679 s = requests.Session()1680 my_adapter = HTTPAdapter()1681 s.mount(mixed_case_prefix, my_adapter)1682

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1683why, one step back
1683 assert s.get_adapter(url_matching_prefix) is my_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1684why, one step back
1684

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1685why, one step back
1685 def test_session_get_adapter_prefix_matching_is_case_insensitive(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1686–1694why, one step back
1686 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1687 url_matching_prefix_with_different_case = (1688 "HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url"1689 )16901691 s = requests.Session()1692 my_adapter = HTTPAdapter()1693 s.mount(mixed_case_prefix, my_adapter)1694

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1695why, one step back
1695 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1696why, one step back
1696

Add two more tests exercising the adapter (#6936)Robinbefore adoptionc65c780

lines 1697–1722why, one step back
1697 def test_session_get_adapter_prefix_with_trailing_slash(self):
1698 # from issue #69351699 prefix = "https://example.com/" # trailing slash1700 url_matching_prefix = "https://example.com/some/path"1701 url_not_matching_prefix = "https://example.com.other.com/some/path"17021703 s = requests.Session()1704 adapter = HTTPAdapter()1705 s.mount(prefix, adapter)17061707 assert s.get_adapter(url_matching_prefix) is adapter1708 assert s.get_adapter(url_not_matching_prefix) is not adapter17091710 def test_session_get_adapter_prefix_without_trailing_slash(self):1711 # from issue #69351712 prefix = "https://example.com" # no trailing slash1713 url_matching_prefix = "https://example.com/some/path"1714 url_extended_hostname = "https://example.com.other.com/some/path"17151716 s = requests.Session()1717 adapter = HTTPAdapter()1718 s.mount(prefix, adapter)17191720 assert s.get_adapter(url_matching_prefix) is adapter1721 assert s.get_adapter(url_extended_hostname) is adapter1722

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1723–1724why, one step back
1723 def test_header_remove_is_case_insensitive(self, httpbin):
1724 # From issue #1321

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1725–1729why, one step back
1725 s = requests.Session()
1726 s.headers["foo"] = "bar"1727 r = s.get(httpbin("get"), headers={"FOO": None})1728 assert "foo" not in r.request.headers1729

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1730why, one step back
1730 def test_params_are_merged_case_sensitive(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1731–1735why, one step back
1731 s = requests.Session()
1732 s.params["foo"] = "bar"1733 r = s.get(httpbin("get"), params={"FOO": "bar"})1734 assert r.json()["args"] == {"foo": "bar", "FOO": "bar"}1735

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1736why, one step back
1736 def test_long_authinfo_in_url(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1737–1742why, one step back
1737 url = "http://{}:{}@{}:9000/path?query#frag".format(
1738 "E8A3BE87-9E3F-4620-8858-95478E385B5B",1739 "EA770032-DA4D-4D84-8CE9-29C6D910BF1E",1740 "exactly-------------sixty-----------three------------characters",1741 )1742 r = requests.Request("GET", url).prepare()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1743why, one step back
1743 assert r.url == url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1744why, one step back
1744

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1745why, one step back
1745 def test_header_keys_are_native(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1746–1749why, one step back
1746 headers = {"unicode": "blah", b"byte": "blah"}
1747 r = requests.Request("GET", httpbin("get"), headers=headers)1748 p = r.prepare()1749

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1750–1751why, one step back
1750 # This is testing that they are builtin strings. A bit weird, but there
1751 # we go.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1752–1754why, one step back
1752 assert "unicode" in p.headers.keys()
1753 assert "byte" in p.headers.keys()1754

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1755–1756why, one step back
1755 def test_header_validation(self, httpbin):
1756 """Ensure prepare_headers regex isn't flagging valid header contents."""

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1757why, one step back
1757 valid_headers = {

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1758–1762why, one step back
1758 "foo": "bar baz qux",
1759 "bar": b"fbbq",1760 "baz": "",1761 "qux": "1",1762 }

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1763–1764why, one step back
1763 r = requests.get(httpbin("get"), headers=valid_headers)
1764 for key in valid_headers.keys():

Merge pull request #6552 from swims-hjkl/issue/test_header_validationNate Prewittbefore adoption839a8ed

line 1765why, one step back
1765 assert valid_headers[key] == r.request.headers[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1766why, one step back
1766

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1767–1775why, one step back
1767 @pytest.mark.parametrize(
1768 "invalid_header, key",1769 (1770 ({"foo": 3}, "foo"),1771 ({"bar": {"foo": "bar"}}, "bar"),1772 ({"baz": ["foo", "bar"]}, "baz"),1773 ),1774 )1775 def test_header_value_not_str(self, httpbin, invalid_header, key):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1776–1777why, one step back
1776 """Ensure the header value is of type string or bytes as
1777 per discussion in GH issue #3386

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1778–1779why, one step back
1778 """
1779 with pytest.raises(InvalidHeader) as excinfo:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1780–1781why, one step back
1780 requests.get(httpbin("get"), headers=invalid_header)
1781 assert key in str(excinfo.value)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1782why, one step back
1782

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1783–1796why, one step back
1783 @pytest.mark.parametrize(
1784 "invalid_header",1785 (1786 {"foo": "bar\r\nbaz: qux"},1787 {"foo": "bar\n\rbaz: qux"},1788 {"foo": "bar\nbaz: qux"},1789 {"foo": "bar\rbaz: qux"},1790 {"fo\ro": "bar"},1791 {"fo\r\no": "bar"},1792 {"fo\n\ro": "bar"},1793 {"fo\no": "bar"},1794 ),1795 )1796 def test_header_no_return_chars(self, httpbin, invalid_header):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1797–1798why, one step back
1797 """Ensure that a header containing return character sequences raise an
1798 exception. Otherwise, multiple headers are created from single string.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1799–1800why, one step back
1799 """
1800 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1801why, one step back
1801 requests.get(httpbin("get"), headers=invalid_header)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1802why, one step back
1802

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1803–1815why, one step back
1803 @pytest.mark.parametrize(
1804 "invalid_header",1805 (1806 {" foo": "bar"},1807 {"\tfoo": "bar"},1808 {" foo": "bar"},1809 {"foo": " bar"},1810 {"foo": " bar"},1811 {"foo": "\tbar"},1812 {" ": "bar"},1813 ),1814 )1815 def test_header_no_leading_space(self, httpbin, invalid_header):

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1816–1817why, one step back
1816 """Ensure headers containing leading whitespace raise
1817 InvalidHeader Error before sending.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1818–1819why, one step back
1818 """
1819 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1820why, one step back
1820 requests.get(httpbin("get"), headers=invalid_header)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1821why, one step back
1821

Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7

lines 1822–1846why, one step back
1822 def test_header_with_subclass_types(self, httpbin):
1823 """If the subclasses does not behave *exactly* like1824 the base bytes/str classes, this is not supported.1825 This test is for backwards compatibility.1826 """18271828 class MyString(str):1829 pass18301831 class MyBytes(bytes):1832 pass18331834 r_str = requests.get(httpbin("get"), headers={MyString("x-custom"): "myheader"})1835 assert r_str.request.headers["x-custom"] == "myheader"18361837 r_bytes = requests.get(1838 httpbin("get"), headers={MyBytes(b"x-custom"): b"myheader"}1839 )1840 assert r_bytes.request.headers["x-custom"] == b"myheader"18411842 r_mixed = requests.get(1843 httpbin("get"), headers={MyString("x-custom"): MyBytes(b"myheader")}1844 )1845 assert r_mixed.request.headers["x-custom"] == b"myheader"1846

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1847why, one step back
1847 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1848why, one step back
1848 def test_can_send_objects_with_files(self, httpbin, files):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1849–1854why, one step back
1849 data = {"a": "this is a string"}
1850 files = {"b": files}1851 r = requests.Request("POST", httpbin("post"), data=data, files=files)1852 p = r.prepare()1853 assert "multipart/form-data" in p.headers["Content-Type"]1854

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1855–1857why, one step back
1855 def test_can_send_file_object_with_non_string_filename(self, httpbin):
1856 f = io.BytesIO()1857 f.name = 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1858–1862why, one step back
1858 r = requests.Request("POST", httpbin("post"), files={"f": f})
1859 p = r.prepare()18601861 assert "multipart/form-data" in p.headers["Content-Type"]1862

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1863why, one step back
1863 def test_autoset_header_values_are_native(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1864–1866why, one step back
1864 data = "this is a string"
1865 length = "16"1866 req = requests.Request("POST", httpbin("post"), data=data)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1867why, one step back
1867 p = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1868–1870why, one step back
1868
1869 assert p.headers["Content-Length"] == length1870

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1871–1872why, one step back
1871 def test_nonhttp_schemes_dont_check_URLs(self):
1872 test_urls = (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1873–1876why, one step back
1873 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
1874 "file:///etc/passwd",1875 "magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431",1876 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1877why, one step back
1877 for test_url in test_urls:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1878why, one step back
1878 req = requests.Request("GET", test_url)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1879–1880why, one step back
1879 preq = req.prepare()
1880 assert test_url == preq.url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1881–1893why, one step back
1881
1882 def test_auth_is_stripped_on_http_downgrade(1883 self, httpbin, httpbin_secure, httpbin_ca_bundle1884 ):1885 r = requests.get(1886 httpbin_secure("redirect-to"),1887 params={"url": httpbin("get")},1888 auth=("user", "pass"),1889 verify=httpbin_ca_bundle,1890 )1891 assert r.history[0].request.headers["Authorization"]1892 assert "Authorization" not in r.request.headers1893

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1894why, one step back
1894 def test_auth_is_retained_for_redirect_on_host(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1895–1898why, one step back
1895 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))
1896 h1 = r.history[0].request.headers["Authorization"]1897 h2 = r.request.headers["Authorization"]1898

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1899why, one step back
1899 assert h1 == h2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1900why, one step back
1900

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1901why, one step back
1901 def test_should_strip_auth_host_change(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1902–1906why, one step back
1902 s = requests.Session()
1903 assert s.should_strip_auth(1904 "http://example.com/foo", "http://another.example.com/"1905 )1906

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1907why, one step back
1907 def test_should_strip_auth_http_downgrade(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1908–1910why, one step back
1908 s = requests.Session()
1909 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1910

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1911why, one step back
1911 def test_should_strip_auth_https_upgrade(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1912–1921why, one step back
1912 s = requests.Session()
1913 assert not s.should_strip_auth(1914 "http://example.com/foo", "https://example.com/bar"1915 )1916 assert not s.should_strip_auth(1917 "http://example.com:80/foo", "https://example.com/bar"1918 )1919 assert not s.should_strip_auth(1920 "http://example.com/foo", "https://example.com:443/bar"1921 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1922why, one step back
1922 # Non-standard ports should trigger stripping

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1923–1929why, one step back
1923 assert s.should_strip_auth(
1924 "http://example.com:8080/foo", "https://example.com/bar"1925 )1926 assert s.should_strip_auth(1927 "http://example.com/foo", "https://example.com:8443/bar"1928 )1929

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1930why, one step back
1930 def test_should_strip_auth_port_change(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1931–1944why, one step back
1931 s = requests.Session()
1932 assert s.should_strip_auth(1933 "http://example.com:1234/foo", "https://example.com:4321/bar"1934 )19351936 @pytest.mark.parametrize(1937 "old_uri, new_uri",1938 (1939 ("https://example.com:443/foo", "https://example.com/bar"),1940 ("http://example.com:80/foo", "http://example.com/bar"),1941 ("https://example.com/foo", "https://example.com:443/bar"),1942 ("http://example.com/foo", "http://example.com:80/bar"),1943 ),1944 )

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1945why, one step back
1945 def test_should_strip_auth_default_port(self, old_uri, new_uri):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1946why, one step back
1946 s = requests.Session()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1947why, one step back
1947 assert not s.should_strip_auth(old_uri, new_uri)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1948why, one step back
1948

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1949why, one step back
1949 def test_manual_redirect_with_partial_body_read(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1950–1951why, one step back
1950 s = requests.Session()
1951 r1 = s.get(httpbin("redirect/2"), allow_redirects=False, stream=True)

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1952–1953why, one step back
1952 assert r1.is_redirect
1953 rg = s.resolve_redirects(r1, r1.request, stream=True)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1954why, one step back
1954

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1955why, one step back
1955 # read only the first eight bytes of the response body,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1956why, one step back
1956 # then follow the redirect

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1957–1959why, one step back
1957 r1.iter_content(8)
1958 r2 = next(rg)1959 assert r2.is_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1960why, one step back
1960

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1961why, one step back
1961 # read all of the response via iter_content,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1962why, one step back
1962 # then follow the redirect

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1963why, one step back
1963 for _ in r2.iter_content():

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1964why, one step back
1964 pass

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

lines 1965–1966why, one step back
1965 r3 = next(rg)
1966 assert not r3.is_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1967why, one step back
1967

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1968why, one step back
1968 def test_prepare_body_position_non_stream(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1969–1970why, one step back
1969 data = b"the data"
1970 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1971why, one step back
1971 assert prep._body_position is None

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1972why, one step back
1972

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1973why, one step back
1973 def test_rewind_body(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1974–1985why, one step back
1974 data = io.BytesIO(b"the data")
1975 prep = requests.Request("GET", "http://example.com", data=data).prepare()1976 assert prep._body_position == 01977 assert prep.body.read() == b"the data"19781979 # the data has all been read1980 assert prep.body.read() == b""19811982 # rewind it back1983 requests.utils.rewind_body(prep)1984 assert prep.body.read() == b"the data"1985

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1986why, one step back
1986 def test_rewind_partially_read_body(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1987why, one step back
1987 data = io.BytesIO(b"the data")

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1988why, one step back
1988 data.read(4) # read some data

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1989why, one step back
1989 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 1990why, one step back
1990 assert prep._body_position == 4

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1991–1999why, one step back
1991 assert prep.body.read() == b"data"
19921993 # the data has all been read1994 assert prep.body.read() == b""19951996 # rewind it back1997 requests.utils.rewind_body(prep)1998 assert prep.body.read() == b"data"1999

Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd

line 2000why, one step back
2000 def test_rewind_body_no_seek(self):

The first 2,000 of 3,039 lines.