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 fileTake 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 back1"""Tests for Requests."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 2why, one step back2Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 3–5why, one step back3import collections4import contextlib5import ioAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 6–9why, one step back6import json7import os8import pickle9import reAdd new test to check netrc auth leak (#6962)danigmbefore adoption7bc4587
line 10why, one step back10import tempfileMerge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a
line 11why, one step back11import threadingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 12why, one step back12import warningsRemove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 13why, one step back13from unittest import mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 14why, one step back14Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 15why, one step back15import pytestWrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 16why, one step back16import urllib3Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 17why, one step back17from urllib3.util import Timeout as Urllib3TimeoutAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 18–28why, one step back1819import 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 back29 is_urllib3_1,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 30–46why, one step back30 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 back47 Timeout,48 TooManyRedirects,49 UnrewindableBodyError,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 50–56why, one step back50)51from requests.exceptions import SSLError as RequestsSSLError52from requests.hooks import default_hooks53from requests.models import PreparedRequest, urlencode54from requests.sessions import SessionRedirectMixin55from requests.structures import CaseInsensitiveDict56Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
line 57why, one step back57from . import SNIMissingWarningAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 58why, one step back58from .compat import StringIOMerge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a
line 59why, one step back59from .testserver.server import TLSServer, consume_socket_contentAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 60–61why, one step back60from .utils import override_environ61Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 62–63why, one step back62# Requests to this URL should always fail with a connection timeout (nothing63# listening on that port)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 64–65why, one step back64TARPIT = "http://10.255.255.1"65Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 66why, one step back66# This is to avoid waiting the timeout of using TARPITAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 67–69why, one step back67INVALID_PROXY = "http://localhost:1"6869try:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 70why, one step back70 from ssl import SSLContextAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 71why, one step back71Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 72–75why, one step back72 del SSLContext73 HAS_MODERN_SSL = True74except ImportError:75 HAS_MODERN_SSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 76–77why, one step back7677try:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 78–81why, one step back78 requests.pyopenssl79 HAS_PYOPENSSL = True80except AttributeError:81 HAS_PYOPENSSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 82–83why, one step back8283Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 84why, one step back84class TestRequests:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 85–86why, one step back85 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")86Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 87–96why, one step back87 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 back97 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F4019899 @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 back111 def test_invalid_url(self, exception, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 112why, one step back112 with pytest.raises(exception):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 113why, one step back113 requests.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 114why, one step back114Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 115–116why, one step back115 def test_basic_building(self):116 req = requests.Request()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 117–119why, one step back117 req.url = "http://kennethreitz.org/"118 req.data = {"life": "42"}119Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 120–121why, one step back120 pr = req.prepare()121 assert pr.url == req.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 122–124why, one step back122 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 back125 def test_no_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 126–129why, one step back126 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 back130 def test_no_body_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 131–134why, one step back131 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 back135 def test_empty_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 136–138why, one step back136 req = requests.Request(method, httpbin(method.lower()), data="").prepare()137 assert req.headers["Content-Length"] == "0"138Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 139why, one step back139 def test_override_content_length(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 140–144why, one step back140 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"144Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 145why, one step back145 def test_path_is_not_double_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 146–162why, one step back146 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 back163 def test_params_are_added_before_fragment(self, url, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 164why, one step back164 request = requests.Request("GET", url, params={"a": "b"}).prepare()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 165why, one step back165 assert request.url == expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 166why, one step back166Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 167why, one step back167 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 back168 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 back175 prep = session.prepare_request(request)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 176–177why, one step back176 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"177Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 178why, one step back178 def test_params_bytes_are_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 179–183why, one step back179 request = requests.Request(180 "GET", "http://example.com", params=b"test=foo"181 ).prepare()182 assert request.url == "http://example.com/?test=foo"183Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 184why, one step back184 def test_binary_put(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 185–187why, one step back185 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 back188 assert isinstance(request.body, bytes)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 189why, one step back189Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 190–191why, one step back190 def test_whitespaces_are_removed_from_url(self):191 # Test for issue #3696Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 192–195why, one step back192 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 back196 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 197–199why, one step back197 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 back200 url = scheme + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 201–204why, one step back201 r = requests.Request("GET", url)202 r = s.send(r.prepare())203 assert r.status_code == 200, f"failed for scheme {scheme}"204Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 205why, one step back205 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 206–213why, one step back206 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 == 200213Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 214why, one step back214 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 215–219why, one step back215 r = requests.get(httpbin("redirect", "1"))216 assert r.status_code == 200217 assert r.history[0].status_code == 302218 assert r.history[0].is_redirect219Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 220why, one step back220 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 221–230why, one step back221 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"230Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 231why, one step back231 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 back232 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")242Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 243why, one step back243 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 244–249why, one step back244 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 == urlUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 250why, one step back250 assert len(e.response.history) == 30Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 251–253why, one step back251 else:252 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")253Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 254why, one step back254 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 back255 s = requests.session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 256why, one step back256 s.max_redirects = 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 257–262why, one step back257 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 == urlUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 263why, one step back263 assert len(e.response.history) == 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 264–268why, one step back264 else:265 pytest.fail(266 "Expected custom max number of redirects to be respected but was not"267 )268Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 269why, one step back269 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 back270 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_redirect275Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 276why, one step back276 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 back277 r = requests.head(httpbin("status", "301"), allow_redirects=True)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 278why, one step back278 print(r.content)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 279–283why, one step back279 assert r.status_code == 200280 assert r.request.method == "HEAD"281 assert r.history[0].status_code == 301282 assert r.history[0].is_redirect283Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 284why, one step back284 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 back285 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_redirect290Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 291why, one step back291 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 back292 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_redirect297Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 298why, one step back298 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 back299 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_redirect304Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 305why, one step back305 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 back306 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_redirect311Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 312why, one step back312 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 back313 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 back317 resp = ses.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 318–322why, one step back318319 # Mimic a redirect response320 resp.status_code = 302321 resp.headers["location"] = "get"322Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 323why, one step back323 # Run request through resolve_redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 324–328why, one step back324 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.headers328Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 329why, one step back329 def test_transfer_enc_removal_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 330–335why, one step back330 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.headers335Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 336why, one step back336 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 337–338why, one step back337 resp = requests.Response()338 resp.raw = io.BytesIO(b"the content")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 339why, one step back339 resp.request = prepAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 340–345why, one step back340 setattr(resp.raw, "release_conn", lambda *args: args)341342 # Mimic a redirect response343 resp.status_code = 302344 resp.headers["location"] = httpbin("get")345Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 346why, one step back346 # Run request through resolve_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 347–351why, one step back347 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.headers351Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 352–353why, one step back352 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 back354 r = requests.get(httpbin("redirect-to?url=get") + fragment)355Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 356why, one step back356 assert len(r.history) > 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 357–359why, one step back357 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment358 assert r.url == httpbin("get") + fragment359Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 360why, one step back360 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 back361 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 == 200367Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 368why, one step back368 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 back369 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 == 200375Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 376why, one step back376 def test_set_cookie_on_301(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 377–381why, one step back377 s = requests.session()378 url = httpbin("cookies/set?foo=bar")379 s.get(url)380 assert s.cookies["foo"] == "bar"381Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 382why, one step back382 def test_cookie_sent_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 383–387why, one step back383 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"]387Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 388why, one step back388 def test_cookie_removed_on_expire(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 389–391why, one step back389 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 back392 s.get(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 393–397why, one step back393 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.cookies397Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 398why, one step back398 def test_cookie_quote_wrapped(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 399why, one step back399 s = requests.session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 400why, one step back400 s.get(httpbin('cookies/set?foo="bar:baz"'))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 401–402why, one step back401 assert s.cookies["foo"] == '"bar:baz"'402Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 403why, one step back403 def test_cookie_persists_via_api(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 404–408why, one step back404 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"]408Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 409why, one step back409 def test_request_cookie_overrides_session_cookie(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 410–413why, one step back410 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 back414 # Session cookie should not be modifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 415–416why, one step back415 assert s.cookies["foo"] == "bar"416Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 417why, one step back417 def test_request_cookies_not_persisted(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 418–419why, one step back418 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 back420 # Sending a request with cookies should not add cookies to the session421 assert not s.cookiesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 422why, one step back422Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 423why, one step back423 def test_generic_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 424–426why, one step back424 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 back427 s.cookies = cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 428–430why, one step back428 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 back431 # Make sure the session cj is still the custom one432 assert s.cookies is cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 433why, one step back433Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 434why, one step back434 def test_param_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 435–441why, one step back435 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"441Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 442–444why, one step back442 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 back445Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 446why, one step back446 See GH #3579Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 447–451why, one step back447 """448 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())449 s = requests.Session()450 s.cookies = cookiejar_from_dict({"cookie": "tasty"})451Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 452why, one step back452 # Prepare request without using SessionAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 453why, one step back453 req = requests.Request("GET", httpbin("headers"), cookies=cj)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 454why, one step back454 prep_req = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 455why, one step back455Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 456–457why, one step back456 # Send request and simulate redirect457 resp = s.send(prep_req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 458–459why, one step back458 resp.status_code = 302459 resp.headers["location"] = httpbin("get")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 460–461why, one step back460 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 back462Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 463–466why, one step back463 # Verify CookieJar isn't being converted to RequestsCookieJar464 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 back467Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 468–470why, one step back468 cookies = {}469 for c in resp.request._cookies:470 cookies[c.name] = c.valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 471–473why, one step back471 assert cookies["foo"] == "bar"472 assert cookies["cookie"] == "tasty"473Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 474why, one step back474 def test_requests_in_history_are_not_overridden(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 475why, one step back475 resp = requests.get(httpbin("redirect/3"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 476–478why, one step back476 urls = [r.url for r in resp.history]477 req_urls = [r.request.url for r in resp.history]478 assert urls == req_urlsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 479why, one step back479Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 480–481why, one step back480 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 back482 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 back486 assert not isinstance(resp.history, tuple)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 487why, one step back487Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 488–489why, one step back488 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 back490 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.headers495Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 496–497why, one step back496 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 back498 ses = requests.Session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 499why, one step back499 ses.headers = collections.OrderedDict()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 500–507why, one step back500 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 back508 items = list(prep.headers.items())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 509–516why, one step back509 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 back517 def test_user_agent_transfers(self, httpbin, key):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 518–520why, one step back518 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 back521 assert heads[key] in r.textAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 522why, one step back522Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 523why, one step back523 def test_HTTP_200_OK_HEAD(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 524–526why, one step back524 r = requests.head(httpbin("get"))525 assert r.status_code == 200526Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 527why, one step back527 def test_HTTP_200_OK_PUT(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 528–530why, one step back528 r = requests.put(httpbin("put"))529 assert r.status_code == 200530Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 531why, one step back531 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 back532 auth = ("user", "pass")533 url = httpbin("basic-auth", "user", "pass")534Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 535why, one step back535 r = requests.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 536–537why, one step back536 assert r.status_code == 200537Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 538–539why, one step back538 r = requests.get(url)539 assert r.status_code == 401Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 540–541why, one step back540541 s = requests.session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 542–543why, one step back542 s.auth = auth543 r = s.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 544–550why, one step back544 assert r.status_code == 200545546 @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 back551 (42, 42),552 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 553–554why, one step back553 ),554 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 555–556why, one step back555 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 back557 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)563Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 564–566why, one step back564 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 back567 """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 back577 # Connecting to an unknown domain should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 578why, one step back578 ("http://doesnotexist.google.com", ConnectionError),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 579why, one step back579 # Connecting to an invalid port should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 580why, one step back580 ("http://localhost:1", ConnectionError),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 581why, one step back581 # Inputing a URL that cannot be parsed should raise an InvalidURL errorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 582–584why, one step back582 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),583 ),584 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 585why, one step back585 def test_errors(self, url, exception):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 586why, one step back586 with pytest.raises(exception):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 587why, one step back587 requests.get(url, timeout=1)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 588why, one step back588Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 589–591why, one step back589 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 back592 requests.get(593 "http://localhost:1", proxies={"http": "non-resolvable-address"}594 )595Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 596why, one step back596 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 back597 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"})608Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 609why, one step back609 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 back610 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())615Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 616why, one step back616 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 back617 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 back621 prepared = session.prepare_request(request)622 session.send(prepared)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 623why, one step back623Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 624why, one step back624 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 back625 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 back629 print(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 630–632why, one step back630 request = requests.Request("GET", url)631 session.send(request.prepare())632Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 633why, one step back633 def test_respect_proxy_env_on_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 634–636why, one step back634 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 back637 session.get(httpbin())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 638why, one step back638Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 639why, one step back639 def test_respect_proxy_env_on_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 640–644why, one step back640 with override_environ(http_proxy=INVALID_PROXY):641 with pytest.raises(ProxyError):642 session = requests.Session()643 session.request(method="GET", url=httpbin())644Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 645–646why, one step back645 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 back647 session = requests.Session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 648why, one step back648 session.headers.update({"Proxy-Authorization": proxy_auth_value})Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 649–651why, one step back649 resp = session.request(method="GET", url=httpbin("get"))650 sent_headers = resp.json().get("headers", {})651Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 652why, one step back652 assert sent_headers.get("Proxy-Authorization") == proxy_auth_valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 653why, one step back653Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 654–656why, one step back654 @pytest.mark.parametrize(655 "url,has_proxy_auth",656 (Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 657–658why, one step back657 ("http://example.com", True),658 ("https://example.com", False),Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 659–660why, one step back659 ),660 )Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 661–663why, one step back661 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 back664 session = requests.Session()665 proxies = {Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 666–667why, one step back666 "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 back668 }Fix linting issuesNate Prewittbefore adoption6e5b15d
line 669why, one step back669 req = requests.Request("GET", url)Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 670–672why, one step back670 prep = req.prepare()671 session.rebuild_proxies(prep, proxies)672Fix linting issuesNate Prewittbefore adoption6e5b15d
line 673why, one step back673 assert ("Proxy-Authorization" in prep.headers) is has_proxy_authMerge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
line 674why, one step back674Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 675why, one step back675 def test_basicauth_with_netrc(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 676–679why, one step back676 auth = ("user", "pass")677 wrong_auth = ("wronguser", "wrongpass")678 url = httpbin("basic-auth", "user", "pass")679Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 680why, one step back680 old_auth = requests.sessions.get_netrc_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 681–683why, one step back681682 try:683Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 684–685why, one step back684 def get_netrc_auth_mock(url):685 return authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 686why, one step back686Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 687why, one step back687 requests.sessions.get_netrc_auth = get_netrc_auth_mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 688–693why, one step back688689 # 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 back694 r = requests.get(url, auth=wrong_auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 695–703why, one step back695 assert r.status_code == 401696697 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 back704 s.auth = wrong_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 705–706why, one step back705 r = s.get(url)706 assert r.status_code == 401Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 707–708why, one step back707 finally:708 requests.sessions.get_netrc_auth = old_authAdd new test to check netrc auth leak (#6962)danigmbefore adoption7bc4587
lines 709–738why, one step back709710 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 back739Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 740why, one step back740 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 741–756why, one step back741 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 == 200756Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 757why, one step back757 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 758–766why, one step back758 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 == 200766Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 767why, one step back767 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 768–770why, one step back768 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 back771 s = requests.Session()772 s.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 773–774why, one step back773 assert s.cookies["fake"] == "fake_value"774Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 775why, one step back775 def test_DIGEST_STREAM(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 776–779why, one step back776 for authtype in self.digest_auth_algo:777 auth = HTTPDigestAuth("user", "pass")778 url = httpbin("digest-auth", "auth", "user", "pass", authtype)779Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 780why, one step back780 r = requests.get(url, auth=auth, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 781–782why, one step back781 assert r.raw.read() != b""782Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 783why, one step back783 r = requests.get(url, auth=auth, stream=False)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 784–785why, one step back784 assert r.raw.read() == b""785Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 786why, one step back786 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 787–797why, one step back787 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 back798 s.auth = authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 799–801why, one step back799 r = s.get(url)800 assert r.status_code == 401801Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 802why, one step back802 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 803–809why, one step back803 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"]809Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 810why, one step back810 def test_POSTBIN_GET_POST_FILES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 811–826why, one step back811 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"])826Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 827why, one step back827 def test_invalid_files_input(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 828–829why, one step back828 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 back830 assert b'name="random-file-1"' not in post.request.body831 assert b'name="random-file-2"' in post.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 832why, one step back832Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 833why, one step back833 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 back834 class TestStream:835 def __init__(self, data):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 836–838why, one step back836 self.data = data.encode()837 self.length = len(self.data)838 self.index = 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 839–840why, one step back839840 def __len__(self):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 841why, one step back841 return self.lengthAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 842why, one step back842Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 843–844why, one step back843 def read(self, size=None):844 if size:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 845why, one step back845 ret = self.data[self.index : self.index + size]Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 846–847why, one step back846 self.index += size847 else:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 848why, one step back848 ret = self.data[self.index :]Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 849–850why, one step back849 self.index = self.length850 return retAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 851–852why, one step back851852 def tell(self):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 853why, one step back853 return self.indexAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 854why, one step back854Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 855–861why, one step back855 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 + offsetAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 862–868why, one step back862863 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 back869 test.seek(2)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 870–873why, one step back870 post2 = requests.post(httpbin("post"), data=test)871 assert post2.status_code == 200872 assert post2.json()["data"] == "st"873Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 874why, one step back874 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 back875 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"])890Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 891–894why, one step back891 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 back895Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 896–897why, one step back896 def __delitem__(self, key):897 del self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 898why, one step back898Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 899–900why, one step back899 def __getitem__(self, key):900 return self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 901why, one step back901Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 902–903why, one step back902 def __setitem__(self, key, value):903 self.data[key] = valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 904–905why, one step back904905 def __iter__(self):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 906why, one step back906 return iter(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 907–908why, one step back907908 def __len__(self):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 909why, one step back909 return len(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 910–915why, one step back910911 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"}915Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 916why, one step back916 def test_conflicting_post_params(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 917–918why, one step back917 url = httpbin("post")918 with open("requirements-dev.txt") as f:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 919why, one step back919 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 920–921why, one step back920 requests.post(url, data='[{"some": "data"}]', files={"some": f})921Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 922why, one step back922 def test_request_ok_set(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 923–925why, one step back923 r = requests.get(httpbin("status", "404"))924 assert not r.ok925Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 926why, one step back926 def test_status_raising(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 927why, one step back927 r = requests.get(httpbin("status", "404"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 928why, one step back928 with pytest.raises(requests.exceptions.HTTPError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 929–933why, one step back929 r.raise_for_status()930931 r = requests.get(httpbin("status", "500"))932 assert not r.ok933Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 934why, one step back934 def test_decompress_gzip(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 935–947why, one step back935 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 back948 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 back950Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 951–952why, one step back951 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 back953 httpbin("put"),954 headers={"Content-Type": "application/octet-stream"},955 data="\xff",956 ) # compat.str is unicode.957Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 958why, one step back958 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 back959 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)960Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 961why, one step back961 def test_invalid_ca_certificate_path(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 962–963why, one step back962 INVALID_PATH = "/garbage"963 with pytest.raises(IOError) as e:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 964why, one step back964 requests.get(httpbin_secure(), verify=INVALID_PATH)Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f
lines 965–967why, one step back965 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 back968 )969Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 970why, one step back970 def test_invalid_ssl_certificate_files(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 971–972why, one step back971 INVALID_PATH = "/garbage"972 with pytest.raises(IOError) as e:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 973why, one step back973 requests.get(httpbin_secure(), cert=INVALID_PATH)Fix CI and build failures (#7190)Nate Prewittbefore adoptionf8bec2f
lines 974–976why, one step back974 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 back977 )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 back988 ({}, True),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 989–1009why, one step back989 ({"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 back1010 def test_env_cert_bundles(self, httpbin, env, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1011why, one step back1011 s = requests.Session()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 1012–1015why, one step back1012 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 back1016 assert settings["verify"] == expected1017Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1018why, one step back1018 def test_http_with_certificate(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1019–1021why, one step back1019 r = requests.get(httpbin(), cert=".")1020 assert r.status_code == 2001021Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
lines 1022–1025why, one step back1022 @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 back1026 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 back1030 warnings_expected = ("SubjectAltNameWarning",)1031 else:1032 warnings_expected = (1033 "SNIMissingWarning",1034 "InsecurePlatformWarning",1035 "SubjectAltNameWarning",1036 )1037Merge pull request #6682 from frenzymadness/pytest8Ian Stapleton Cordascobefore adoption31ebb81
line 1038why, one step back1038 with pytest.warns() as warning_records:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1039–1048why, one step back1039 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 back1049 assert warnings_category == warnings_expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1050why, one step back1050Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1051why, one step back1051 def test_certificate_failure(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1052why, one step back1052 """Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1053why, one step back1053 When underlying SSL problems occur, an SSLError is raised.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1054why, one step back1054 """Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1055why, one step back1055 with pytest.raises(RequestsSSLError):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1056–1057why, one step back1056 # Our local httpbin does not have a trusted CA, so this call will1057 # fail if we use our default trust bundle.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1058–1059why, one step back1058 requests.get(httpbin_secure("status", "200"))1059Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1060why, one step back1060 def test_urlencoded_get_query_multivalued_param(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1061–1064why, one step back1061 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})1062 assert r.status_code == 2001063 assert r.url == httpbin("get?test=foo&test=baz")1064Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1065why, one step back1065 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 back1066 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"1071Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1072why, one step back1072 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 back1073 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 back1080 assert r.status_code == 20010811082 @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 back1091 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 back1092 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 back1098 assert r.status_code == 2001099Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1100why, one step back1100 def test_unicode_multipart_post_fieldnames(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1101why, one step back1101 filename = os.path.splitext(__file__)[0] + ".py"Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1102–1110why, one step back1102 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()1110Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1111why, one step back1111 assert b'name="stuff"' in prep.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1112–1113why, one step back1112 assert b"name=\"b'stuff'\"" not in prep.body1113Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1114why, one step back1114 def test_unicode_method_name(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1115–1121why, one step back1115 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 back1122 assert r.status_code == 2001123Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1124why, one step back1124 def test_unicode_method_name_with_request_object(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1125why, one step back1125 s = requests.Session()Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1126–1129why, one step back1126 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 back1130 assert isinstance(prep.method, builtin_str)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1131–1135why, one step back1131 assert prep.method == "POST"11321133 resp = s.send(prep)1134 assert resp.status_code == 2001135Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1136why, one step back1136 def test_non_prepared_request_error(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1137–1140why, one step back1137 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 back1141 s.send(req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1142–1143why, one step back1142 assert str(e.value) == "You can only send PreparedRequests."1143Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1144why, one step back1144 def test_custom_content_type(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1145–1146why, one step back1145 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 back1147 data = {"stuff": json.dumps({"a": 123})}Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1148–1152why, one step back1148 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 back1153 assert r.status_code == 200Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1154why, one step back1154 assert b"text/py-content-type" in r.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1155why, one step back1155Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1156why, one step back1156 def test_hook_receives_request_arguments(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1157why, one step back1157 def hook(resp, **kwargs):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1158–1159why, one step back1158 assert resp is not None1159 assert kwargs != {}Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1160–1163why, one step back11601161 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 back1164 s.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1165why, one step back1165Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1166why, one step back1166 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 back1167 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]1176Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1177why, one step back1177 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 back1178 def hook1(*args, **kwargs):1179 pass11801181 def hook2(*args, **kwargs):1182 pass1183Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1184why, one step back1184 assert hook1 is not hook2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1185–1190why, one step back1185 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]1190Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1191why, one step back1191 def test_prepared_request_hook(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1192why, one step back1192 def hook(resp, **kwargs):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1193why, one step back1193 resp.hook_working = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1194–1196why, one step back1194 return resp11951196 req = requests.Request("GET", httpbin(), hooks={"response": hook})Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1197why, one step back1197 prep = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1198–1204why, one step back11981199 s = requests.Session()1200 s.proxies = getproxies()1201 resp = s.send(prep)12021203 assert hasattr(resp, "hook_working")1204Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1205–1207why, one step back1205 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 back1208 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1209why, one step back1209 return rAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1210–1211why, one step back12101211 req = requests.Request("GET", httpbin("headers"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1212why, one step back1212 assert not req.authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1213–1214why, one step back12131214 s = requests.Session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1215why, one step back1215 s.auth = DummyAuth()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1216–1221why, one step back12161217 prep = s.prepare_request(req)1218 resp = s.send(prep)12191220 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1221Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1222why, one step back1222 def test_prepare_request_with_bytestring_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1223–1225why, one step back1223 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 back1226 assert prep.url == "https://httpbin.org/"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1227why, one step back1227Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1228why, one step back1228 def test_request_with_bytestring_host(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1229why, one step back1229 s = requests.Session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1230why, one step back1230 resp = s.request(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1231–1232why, one step back1231 "GET",1232 httpbin("cookies/set?cookie=value"),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1233why, one step back1233 allow_redirects=False,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1234–1237why, one step back1234 headers={"Host": b"httpbin.org"},1235 )1236 assert resp.cookies.get("cookie") == "value"1237Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1238why, one step back1238 def test_links(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1239why, one step back1239 r = requests.Response()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1240why, one step back1240 r.headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1241–1263why, one step back1241 "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"1263Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1264why, one step back1264 def test_cookie_parameters(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1265–1266why, one step back1265 key = "some_cookie"1266 value = "some_value"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1267why, one step back1267 secure = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1268–1271why, one step back1268 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 back1272 jar.set(key, value, secure=secure, domain=domain, rest=rest)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1273why, one step back1273Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1274why, one step back1274 assert len(jar) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1275–1276why, one step back1275 assert "some_cookie" in jar1276Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1277–1279why, one step back1277 cookie = list(jar)[0]1278 assert cookie.secure == secure1279 assert cookie.domain == domainAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1280–1281why, one step back1280 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]1281Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1282why, one step back1282 def test_cookie_as_dict_keeps_len(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1283–1296why, one step back1283 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())1296Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1297–1300why, one step back1297 assert len(jar) == 21298 assert len(d1) == 21299 assert len(d2) == 21300 assert len(d3) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1301why, one step back1301Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1302why, one step back1302 def test_cookie_as_dict_keeps_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1303–1320why, one step back1303 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"1320Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1321why, one step back1321 def test_cookie_as_dict_keys(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1322–1331why, one step back1322 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)1331Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1332–1335why, one step back1332 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 back1336Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1337why, one step back1337 def test_cookie_as_dict_values(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1338–1347why, one step back1338 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)1347Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1348–1351why, one step back1348 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 back1352Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1353why, one step back1353 def test_cookie_as_dict_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1354–1364why, one step back1354 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 back1365 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 back1368Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1369why, one step back1369 def test_cookie_duplicate_names_different_domains(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1370–1375why, one step back1370 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 back1376 jar.set(key, value, domain=domain1)1377 jar.set(key, value, domain=domain2)1378 assert key in jarAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1379why, one step back1379 items = jar.items()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1380why, one step back1380 assert len(items) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1381why, one step back1381Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1382why, one step back1382 # Verify that CookieConflictError is raised if domain is not specifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1383–1385why, one step back1383 with pytest.raises(requests.cookies.CookieConflictError):1384 jar.get(key)1385Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1386–1388why, one step back1386 # Verify that CookieConflictError is not raised if domain is specified1387 cookie = jar.get(key, domain=domain1)1388 assert cookie == valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1389why, one step back1389Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1390why, one step back1390 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 back1391 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 back1396 jar.set(key, value, path=path)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1397–1400why, one step back1397 jar.set(key, value)1398 with pytest.raises(requests.cookies.CookieConflictError):1399 jar.get(key)1400Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1401–1402why, one step back1401 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 back1403 pass14041405 jar = requests.cookies.RequestsCookieJar()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1406–1407why, one step back1406 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 back1408Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1409why, one step back1409 def test_time_elapsed_blank(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1410why, one step back1410 r = requests.get(httpbin("get"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1411why, one step back1411 td = r.elapsedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1412–1414why, one step back1412 total_seconds = (1413 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61414 ) / 10**6Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1415why, one step back1415 assert total_seconds > 0.0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1416why, one step back1416Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1417why, one step back1417 def test_empty_response_has_content_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1418–1420why, one step back1418 r = requests.Response()1419 assert r.content is None1420Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1421why, one step back1421 def test_response_is_iterable(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1422–1423why, one step back1422 r = requests.Response()1423 io = StringIO.StringIO("abc")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1424why, one step back1424 read_ = io.readAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1425why, one step back1425Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1426–1427why, one step back1426 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 back14281429 setattr(io, "read", read_mock)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1430–1432why, one step back1430 r.raw = io1431 assert next(iter(r))1432 io.close()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1433why, one step back1433Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1434–1436why, one step back1434 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 back1437 """1438 r = requests.Response()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1439why, one step back1439 r._content_consumed = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1440–1445why, one step back1440 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)1445Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1446why, one step back1446 # also for streamingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1447–1452why, one step back1447 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)1452Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1453–1454why, one step back1453 def test_response_reason_unicode(self):1454 # check for unicode HTTP statusAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1455–1457why, one step back1455 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 back1458 r.status_code = 404Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1459why, one step back1459 r.encoding = NoneUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1460why, one step back1460 assert not r.ok # old behaviour - crashes hereAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1461why, one step back1461Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1462–1463why, one step back1462 def test_response_reason_unicode_fallback(self):1463 # check raise_status falls back to ISO-8859-1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1464–1467why, one step back1464 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 back1468 r.status_code = 500Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1469why, one step back1469 r.encoding = NoneUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1470why, one step back1470 with pytest.raises(requests.exceptions.HTTPError) as e:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1471why, one step back1471 r.raise_for_status()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1472why, one step back1472 assert reason in e.value.args[0]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1473why, one step back1473Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1474–1476why, one step back1474 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 back1477 """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 back1480 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 back14821483 r = requests.Response()1484 r.raw = io.BytesIO(b"the content")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1485why, one step back1485 chunks = r.iter_content(None)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1486–1490why, one step back1486 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 back1491 chunks = r.iter_content("1024")Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1492–1495why, one step back14921493 @pytest.mark.parametrize(1494 "exception, args, expected",1495 (Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1496–1497why, one step back1496 (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 back1498 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1499why, one step back1499 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1500–1501why, one step back1500 ),1501 )Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1502why, one step back1502 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 back1503 r = requests.Response()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1504why, one step back1504 r.raw = mock.Mock()Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1505–1507why, one step back1505 # ReadTimeoutError can't be initialized by mock1506 # 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 back1508Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1509–1510why, one step back1509 with pytest.raises(expected):1510 next(r.iter_content(1024))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1511why, one step back1511Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1512why, one step back1512 def test_request_and_response_are_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1513–1514why, one step back1513 r = requests.get(httpbin("get"))1514Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1515–1516why, one step back1515 # verify we can pickle the original request1516 assert pickle.loads(pickle.dumps(r.request))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1517why, one step back1517Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1518–1522why, one step back1518 # verify we can pickle the response and that we have access to1519 # the original request.1520 pr = pickle.loads(pickle.dumps(r))1521 assert r.request.url == pr.request.url1522 assert r.request.headers == pr.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1523why, one step back1523Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1524why, one step back1524 def test_prepared_request_is_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1525–1537why, one step back1525 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 == 2001537Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1538why, one step back1538 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 back1539 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 back15421543 # 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 == 2001553Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1554why, one step back1554 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 back1555 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())1556 p = r.prepare()1557Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1558why, one step back1558 # Verify PreparedRequest can be pickledAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1559–1562why, one step back1559 r = pickle.loads(pickle.dumps(p))1560 assert r.url == p.url1561 assert r.headers == p.headers1562 assert r.body == p.bodyUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1563why, one step back1563 assert r.hooks == p.hooksAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1564–1569why, one step back15641565 # Verify unpickled PreparedRequest sends properly1566 s = requests.Session()1567 resp = s.send(r)1568 assert resp.status_code == 2001569Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1570–1571why, one step back1570 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 back1572 with pytest.raises(ValueError):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1573why, one step back1573 requests.Session().send(r)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1574why, one step back1574Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1575–1579why, one step back1575 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 back1580 assert error.response == response1581 error = requests.exceptions.HTTPError("message", response=response)1582 assert str(error) == "message"1583 assert error.response == response1584Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1585why, one step back1585 def test_session_pickling(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1586–1588why, one step back1586 r = requests.Request("GET", httpbin("get"))1587 s = requests.Session()1588Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1589why, one step back1589 s = pickle.loads(pickle.dumps(s))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1590–1594why, one step back1590 s.proxies = getproxies()15911592 r = s.send(r.prepare())1593 assert r.status_code == 2001594Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1595–1596why, one step back1595 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 back1597 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 back1601 headers = r.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1602–1605why, one step back1602 assert headers["accept"] == "application/json"1603 assert headers["Accept"] == "application/json"1604 assert headers["ACCEPT"] == "application/json"1605Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1606why, one step back1606 def test_uppercase_scheme_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1607why, one step back1607 parts = urlparse(httpbin("html"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1608why, one step back1608 url = "HTTP://" + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1609–1610why, one step back1609 r = requests.get(httpbin("redirect-to"), params={"url": url})1610 assert r.status_code == 200Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1611why, one step back1611 assert r.url.lower() == url.lower()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1612why, one step back1612Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1613why, one step back1613 def test_transport_adapter_ordering(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1614–1644why, one step back1614 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 back1645 s2 = requests.Session()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1646–1650why, one step back1646 s2.adapters = {"http://": HTTPAdapter()}1647 s2.mount("https://", HTTPAdapter())1648 assert "http://" in s2.adapters1649 assert "https://" in s2.adapters1650Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1651why, one step back1651 def test_session_get_adapter_prefix_matching(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1652–1659why, one step back1652 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 back1660 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 back1664Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1665why, one step back1665 assert s.get_adapter(url_matching_only_prefix) is prefix_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1666–1674why, one step back1666 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 )1674Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1675why, one step back1675 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 back1676 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)1682Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1683why, one step back1683 assert s.get_adapter(url_matching_prefix) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1684why, one step back1684Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1685why, one step back1685 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 back1686 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)1694Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1695why, one step back1695 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1696why, one step back1696Add two more tests exercising the adapter (#6936)Robinbefore adoptionc65c780
lines 1697–1722why, one step back1697 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 adapter1722Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1723–1724why, one step back1723 def test_header_remove_is_case_insensitive(self, httpbin):1724 # From issue #1321Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1725–1729why, one step back1725 s = requests.Session()1726 s.headers["foo"] = "bar"1727 r = s.get(httpbin("get"), headers={"FOO": None})1728 assert "foo" not in r.request.headers1729Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1730why, one step back1730 def test_params_are_merged_case_sensitive(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1731–1735why, one step back1731 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"}1735Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1736why, one step back1736 def test_long_authinfo_in_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1737–1742why, one step back1737 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 back1743 assert r.url == urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1744why, one step back1744Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1745why, one step back1745 def test_header_keys_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1746–1749why, one step back1746 headers = {"unicode": "blah", b"byte": "blah"}1747 r = requests.Request("GET", httpbin("get"), headers=headers)1748 p = r.prepare()1749Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1750–1751why, one step back1750 # This is testing that they are builtin strings. A bit weird, but there1751 # we go.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1752–1754why, one step back1752 assert "unicode" in p.headers.keys()1753 assert "byte" in p.headers.keys()1754Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1755–1756why, one step back1755 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 back1757 valid_headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1758–1762why, one step back1758 "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 back1763 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 back1765 assert valid_headers[key] == r.request.headers[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1766why, one step back1766Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1767–1775why, one step back1767 @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 back1776 """Ensure the header value is of type string or bytes as1777 per discussion in GH issue #3386Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1778–1779why, one step back1778 """1779 with pytest.raises(InvalidHeader) as excinfo:Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1780–1781why, one step back1780 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 back1782Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1783–1796why, one step back1783 @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 back1797 """Ensure that a header containing return character sequences raise an1798 exception. Otherwise, multiple headers are created from single string.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1799–1800why, one step back1799 """1800 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1801why, one step back1801 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1802why, one step back1802Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1803–1815why, one step back1803 @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 back1816 """Ensure headers containing leading whitespace raise1817 InvalidHeader Error before sending.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1818–1819why, one step back1818 """1819 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1820why, one step back1820 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1821why, one step back1821Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7
lines 1822–1846why, one step back1822 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"1846Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1847why, one step back1847 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1848why, one step back1848 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 back1849 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"]1854Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1855–1857why, one step back1855 def test_can_send_file_object_with_non_string_filename(self, httpbin):1856 f = io.BytesIO()1857 f.name = 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1858–1862why, one step back1858 r = requests.Request("POST", httpbin("post"), files={"f": f})1859 p = r.prepare()18601861 assert "multipart/form-data" in p.headers["Content-Type"]1862Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1863why, one step back1863 def test_autoset_header_values_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1864–1866why, one step back1864 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 back1867 p = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1868–1870why, one step back18681869 assert p.headers["Content-Length"] == length1870Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1871–1872why, one step back1871 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 back1873 "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 back1877 for test_url in test_urls:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1878why, one step back1878 req = requests.Request("GET", test_url)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1879–1880why, one step back1879 preq = req.prepare()1880 assert test_url == preq.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1881–1893why, one step back18811882 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.headers1893Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1894why, one step back1894 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 back1895 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))1896 h1 = r.history[0].request.headers["Authorization"]1897 h2 = r.request.headers["Authorization"]1898Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1899why, one step back1899 assert h1 == h2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1900why, one step back1900Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1901why, one step back1901 def test_should_strip_auth_host_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1902–1906why, one step back1902 s = requests.Session()1903 assert s.should_strip_auth(1904 "http://example.com/foo", "http://another.example.com/"1905 )1906Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1907why, one step back1907 def test_should_strip_auth_http_downgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1908–1910why, one step back1908 s = requests.Session()1909 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1910Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1911why, one step back1911 def test_should_strip_auth_https_upgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1912–1921why, one step back1912 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 back1922 # Non-standard ports should trigger strippingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1923–1929why, one step back1923 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 )1929Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1930why, one step back1930 def test_should_strip_auth_port_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1931–1944why, one step back1931 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 back1945 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 back1946 s = requests.Session()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1947why, one step back1947 assert not s.should_strip_auth(old_uri, new_uri)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1948why, one step back1948Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1949why, one step back1949 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 back1950 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 back1952 assert r1.is_redirect1953 rg = s.resolve_redirects(r1, r1.request, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1954why, one step back1954Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1955why, one step back1955 # read only the first eight bytes of the response body,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1956why, one step back1956 # then follow the redirectUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1957–1959why, one step back1957 r1.iter_content(8)1958 r2 = next(rg)1959 assert r2.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1960why, one step back1960Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1961why, one step back1961 # read all of the response via iter_content,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1962why, one step back1962 # then follow the redirectUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1963why, one step back1963 for _ in r2.iter_content():Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1964why, one step back1964 passUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1965–1966why, one step back1965 r3 = next(rg)1966 assert not r3.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1967why, one step back1967Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1968why, one step back1968 def test_prepare_body_position_non_stream(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1969–1970why, one step back1969 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 back1971 assert prep._body_position is NoneAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1972why, one step back1972Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1973why, one step back1973 def test_rewind_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1974–1985why, one step back1974 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"1985Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1986why, one step back1986 def test_rewind_partially_read_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1987why, one step back1987 data = io.BytesIO(b"the data")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1988why, one step back1988 data.read(4) # read some dataAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1989why, one step back1989 prep = requests.Request("GET", "http://example.com", data=data).prepare()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 1990why, one step back1990 assert prep._body_position == 4Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1991–1999why, one step back1991 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"1999Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 2000why, one step back2000 def test_rewind_body_no_seek(self):The first 2,000 of 3,039 lines.