test_lowlevel.py
This file
Path
tests/test_lowlevel.py
428 lines · 15.0 KiB · Python
Last changed by
Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
History of this fileTake it
The walk stopped after 200 commits: lines older than 962c898 point at it.
Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 1–2why, one step back1import threading2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 3why, one step back3import pytestMerge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 4–5why, one step back4from tests.testserver.server import Server, consume_socket_content5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 6why, one step back6import requestsFix inconsistent exception for JSONDecode error (#6097)Nate Prewittbefore adoption2d55176
line 7why, one step back7from requests.compat import JSONDecodeErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 8why, one step back8Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 9–11why, one step back9from .utils import override_environ1011Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 12–16why, one step back12def echo_response_handler(sock):13 """Simple handler that will take request and echo it back to requester."""14 request_content = consume_socket_content(sock, timeout=0.5)1516 text_200 = (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 17–19why, one step back17 b"HTTP/1.1 200 OK\r\n"18 b"Content-Length: %d\r\n\r\n"19 b"%s"Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 20–23why, one step back20 ) % (len(request_content), request_content)21 sock.send(text_200)2223Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 24–27why, one step back24def test_chunked_upload():25 """can safely send generators"""26 close_server = threading.Event()27 server = Server.basic_response_server(wait_to_close_event=close_server)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 28why, one step back28 data = iter([b"a", b"b", b"c"])Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 29–30why, one step back2930 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 31why, one step back31 url = f"http://{host}:{port}/"Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 32–35why, one step back32 r = requests.post(url, data=data, stream=True)33 close_server.set() # release server block3435 assert r.status_code == 200Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 36why, one step back36 assert r.request.headers["Transfer-Encoding"] == "chunked"Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 37–38why, one step back3738Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)Ben Li-Sauerwinebefore adoption2d30aeb
lines 39–45why, one step back39def test_chunked_encoding_error():40 """get a ChunkedEncodingError if the server returns a bad response"""4142 def incomplete_chunked_response_handler(sock):43 request_content = consume_socket_content(sock, timeout=0.5)4445 # The server never ends the request and doesn't provide any valid chunksAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 46–49why, one step back46 sock.send(47 b"HTTP/1.1 200 OK\r\n"48 b"Transfer-Encoding: chunked\r\n"49 )Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)Ben Li-Sauerwinebefore adoption2d30aeb
lines 50–56why, one step back5051 return request_content5253 close_server = threading.Event()54 server = Server(incomplete_chunked_response_handler)5556 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 57why, one step back57 url = f"http://{host}:{port}/"Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)Ben Li-Sauerwinebefore adoption2d30aeb
line 58why, one step back58 with pytest.raises(requests.exceptions.ChunkedEncodingError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 59why, one step back59 requests.get(url)Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)Ben Li-Sauerwinebefore adoption2d30aeb
line 60why, one step back60 close_server.set() # release server blockMerge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 61–67why, one step back616263def test_chunked_upload_uses_only_specified_host_header():64 """Ensure we use only the specified Host header for chunked requests."""65 close_server = threading.Event()66 server = Server(echo_response_handler, wait_to_close_event=close_server)67Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 68–69why, one step back68 data = iter([b"a", b"b", b"c"])69 custom_host = "sample-host"Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 70–71why, one step back7071 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 72–73why, one step back72 url = f"http://{host}:{port}/"73 r = requests.post(url, data=data, headers={"Host": custom_host}, stream=True)Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 74–75why, one step back74 close_server.set() # release server block75Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 76why, one step back76 expected_header = b"Host: %s\r\n" % custom_host.encode("utf-8")Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
line 77why, one step back77 assert expected_header in r.contentAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 78why, one step back78 assert r.content.count(b"Host: ") == 1Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 79–85why, one step back798081def test_chunked_upload_doesnt_skip_host_header():82 """Ensure we don't omit all Host headers with chunked requests."""83 close_server = threading.Event()84 server = Server(echo_response_handler, wait_to_close_event=close_server)85Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 86why, one step back86 data = iter([b"a", b"b", b"c"])Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 87–88why, one step back8788 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 89–90why, one step back89 expected_host = f"{host}:{port}"90 url = f"http://{host}:{port}/"Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
lines 91–93why, one step back91 r = requests.post(url, data=data, stream=True)92 close_server.set() # release server block93Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 94why, one step back94 expected_header = b"Host: %s\r\n" % expected_host.encode("utf-8")Merge pull request #5391 from hodbn/fix-5274Nate Prewittbefore adoption7556ea4
line 95why, one step back95 assert expected_header in r.contentAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 96why, one step back96 assert r.content.count(b"Host: ") == 1Add a test which verifies that ChunkedEncodingError is emitted if an invalid Transfer-Encoding: chunked response is returned. (#5906)Ben Li-Sauerwinebefore adoption2d30aeb
lines 97–98why, one step back9798Appropriately handle urllib3's InvalidHeader exception (#5914)Nate Prewittbefore adoption1096835
lines 99–105why, one step back99def test_conflicting_content_lengths():100 """Ensure we correctly throw an InvalidHeader error if multiple101 conflicting Content-Length headers are returned.102 """103104 def multiple_content_length_response_handler(sock):105 request_content = consume_socket_content(sock, timeout=0.5)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 106–113why, one step back106 response = (107 b"HTTP/1.1 200 OK\r\n"108 b"Content-Type: text/plain\r\n"109 b"Content-Length: 16\r\n"110 b"Content-Length: 32\r\n\r\n"111 b"-- Bad Actor -- Original Content\r\n"112 )113 sock.send(response)Appropriately handle urllib3's InvalidHeader exception (#5914)Nate Prewittbefore adoption1096835
lines 114–120why, one step back114115 return request_content116117 close_server = threading.Event()118 server = Server(multiple_content_length_response_handler)119120 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 121why, one step back121 url = f"http://{host}:{port}/"Appropriately handle urllib3's InvalidHeader exception (#5914)Nate Prewittbefore adoption1096835
line 122why, one step back122 with pytest.raises(requests.exceptions.InvalidHeader):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 123why, one step back123 requests.get(url)Appropriately handle urllib3's InvalidHeader exception (#5914)Nate Prewittbefore adoption1096835
lines 124–126why, one step back124 close_server.set()125126Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 127–179why, one step back127def test_digestauth_401_count_reset_on_redirect():128 """Ensure we correctly reset num_401_calls after a successful digest auth,129 followed by a 302 redirect to another digest auth prompt.130131 See https://github.com/psf/requests/issues/1979.132 """133 text_401 = (b'HTTP/1.1 401 UNAUTHORIZED\r\n'134 b'Content-Length: 0\r\n'135 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'136 b', opaque="372825293d1c26955496c80ed6426e9e", '137 b'realm="me@kennethreitz.com", qop=auth\r\n\r\n')138139 text_302 = (b'HTTP/1.1 302 FOUND\r\n'140 b'Content-Length: 0\r\n'141 b'Location: /\r\n\r\n')142143 text_200 = (b'HTTP/1.1 200 OK\r\n'144 b'Content-Length: 0\r\n\r\n')145146 expected_digest = (b'Authorization: Digest username="user", '147 b'realm="me@kennethreitz.com", '148 b'nonce="6bf5d6e4da1ce66918800195d6b9130d", uri="/"')149150 auth = requests.auth.HTTPDigestAuth('user', 'pass')151152 def digest_response_handler(sock):153 # Respond to initial GET with a challenge.154 request_content = consume_socket_content(sock, timeout=0.5)155 assert request_content.startswith(b"GET / HTTP/1.1")156 sock.send(text_401)157158 # Verify we receive an Authorization header in response, then redirect.159 request_content = consume_socket_content(sock, timeout=0.5)160 assert expected_digest in request_content161 sock.send(text_302)162163 # Verify Authorization isn't sent to the redirected host,164 # then send another challenge.165 request_content = consume_socket_content(sock, timeout=0.5)166 assert b'Authorization:' not in request_content167 sock.send(text_401)168169 # Verify Authorization is sent correctly again, and return 200 OK.170 request_content = consume_socket_content(sock, timeout=0.5)171 assert expected_digest in request_content172 sock.send(text_200)173174 return request_content175176 close_server = threading.Event()177 server = Server(digest_response_handler, wait_to_close_event=close_server)178179 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 180why, one step back180 url = f'http://{host}:{port}/'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 181–229why, one step back181 r = requests.get(url, auth=auth)182 # Verify server succeeded in authenticating.183 assert r.status_code == 200184 # Verify Authorization was sent in final request.185 assert 'Authorization' in r.request.headers186 assert r.request.headers['Authorization'].startswith('Digest ')187 # Verify redirect happened as we expected.188 assert r.history[0].status_code == 302189 close_server.set()190191192def test_digestauth_401_only_sent_once():193 """Ensure we correctly respond to a 401 challenge once, and then194 stop responding if challenged again.195 """196 text_401 = (b'HTTP/1.1 401 UNAUTHORIZED\r\n'197 b'Content-Length: 0\r\n'198 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'199 b', opaque="372825293d1c26955496c80ed6426e9e", '200 b'realm="me@kennethreitz.com", qop=auth\r\n\r\n')201202 expected_digest = (b'Authorization: Digest username="user", '203 b'realm="me@kennethreitz.com", '204 b'nonce="6bf5d6e4da1ce66918800195d6b9130d", uri="/"')205206 auth = requests.auth.HTTPDigestAuth('user', 'pass')207208 def digest_failed_response_handler(sock):209 # Respond to initial GET with a challenge.210 request_content = consume_socket_content(sock, timeout=0.5)211 assert request_content.startswith(b"GET / HTTP/1.1")212 sock.send(text_401)213214 # Verify we receive an Authorization header in response, then215 # challenge again.216 request_content = consume_socket_content(sock, timeout=0.5)217 assert expected_digest in request_content218 sock.send(text_401)219220 # Verify the client didn't respond to second challenge.221 request_content = consume_socket_content(sock, timeout=0.5)222 assert request_content == b''223224 return request_content225226 close_server = threading.Event()227 server = Server(digest_failed_response_handler, wait_to_close_event=close_server)228229 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 230why, one step back230 url = f'http://{host}:{port}/'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 231–266why, one step back231 r = requests.get(url, auth=auth)232 # Verify server didn't authenticate us.233 assert r.status_code == 401234 assert r.history[0].status_code == 401235 close_server.set()236237238def test_digestauth_only_on_4xx():239 """Ensure we only send digestauth on 4xx challenges.240241 See https://github.com/psf/requests/issues/3772.242 """243 text_200_chal = (b'HTTP/1.1 200 OK\r\n'244 b'Content-Length: 0\r\n'245 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'246 b', opaque="372825293d1c26955496c80ed6426e9e", '247 b'realm="me@kennethreitz.com", qop=auth\r\n\r\n')248249 auth = requests.auth.HTTPDigestAuth('user', 'pass')250251 def digest_response_handler(sock):252 # Respond to GET with a 200 containing www-authenticate header.253 request_content = consume_socket_content(sock, timeout=0.5)254 assert request_content.startswith(b"GET / HTTP/1.1")255 sock.send(text_200_chal)256257 # Verify the client didn't respond with auth.258 request_content = consume_socket_content(sock, timeout=0.5)259 assert request_content == b''260261 return request_content262263 close_server = threading.Event()264 server = Server(digest_response_handler, wait_to_close_event=close_server)265266 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 267why, one step back267 url = f'http://{host}:{port}/'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 268–283why, one step back268 r = requests.get(url, auth=auth)269 # Verify server didn't receive auth from us.270 assert r.status_code == 200271 assert len(r.history) == 0272 close_server.set()273274275_schemes_by_var_prefix = [276 ('http', ['http']),277 ('https', ['https']),278 ('all', ['http', 'https']),279]280281_proxy_combos = []282for prefix, schemes in _schemes_by_var_prefix:283 for scheme in schemes:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 284why, one step back284 _proxy_combos.append((f"{prefix}_proxy", scheme))Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 285–290why, one step back285286_proxy_combos += [(var.upper(), scheme) for var, scheme in _proxy_combos]287288289@pytest.mark.parametrize("var,scheme", _proxy_combos)290def test_use_proxy_from_environment(httpbin, var, scheme):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 291why, one step back291 url = f"{scheme}://httpbin.org"Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 292–293why, one step back292 fake_proxy = Server() # do nothing with the requests; just close the socket293 with fake_proxy as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 294why, one step back294 proxy_url = f"socks5://{host}:{port}"Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 295–308why, one step back295 kwargs = {var: proxy_url}296 with override_environ(**kwargs):297 # fake proxy's lack of response will cause a ConnectionError298 with pytest.raises(requests.exceptions.ConnectionError):299 requests.get(url)300301 # the fake proxy received a request302 assert len(fake_proxy.handler_results) == 1303304 # it had actual content (not checking for SOCKS protocol for now)305 assert len(fake_proxy.handler_results[0]) > 0306307308def test_redirect_rfc1808_to_non_ascii_location():Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 309why, one step back309 path = 'š'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 310–314why, one step back310 expected_path = b'%C5%A1'311 redirect_request = [] # stores the second request to the server312313 def redirect_resp_handler(sock):314 consume_socket_content(sock, timeout=0.5)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 315why, one step back315 location = f'//{host}:{port}/{path}'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
line 316why, one step back316 sock.send(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 317–322why, one step back317 (318 b'HTTP/1.1 301 Moved Permanently\r\n'319 b'Content-Length: 0\r\n'320 b'Location: %s\r\n'321 b'\r\n'322 ) % location.encode('utf8')Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 323–330why, one step back323 )324 redirect_request.append(consume_socket_content(sock, timeout=0.5))325 sock.send(b'HTTP/1.1 200 OK\r\n\r\n')326327 close_server = threading.Event()328 server = Server(redirect_resp_handler, wait_to_close_event=close_server)329330 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 331why, one step back331 url = f'http://{host}:{port}'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 332–336why, one step back332 r = requests.get(url=url, allow_redirects=True)333 assert r.status_code == 200334 assert len(r.history) == 1335 assert r.history[0].status_code == 301336 assert redirect_request[0].startswith(b'GET /' + expected_path + b' HTTP/1.1')Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 337why, one step back337 assert r.url == '{}/{}'.format(url, expected_path.decode('ascii'))Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 338–340why, one step back338339 close_server.set()340Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 341why, one step back341Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 342–344why, one step back342def test_fragment_not_sent_with_request():343 """Verify that the fragment portion of a URI isn't sent to the server."""344 close_server = threading.Event()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 345why, one step back345 server = Server(echo_response_handler, wait_to_close_event=close_server)Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 346–347why, one step back346347 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 348why, one step back348 url = f'http://{host}:{port}/path/to/thing/#view=edit&token=hunter2'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 349–362why, one step back349 r = requests.get(url)350 raw_request = r.content351352 assert r.status_code == 200353 headers, body = raw_request.split(b'\r\n\r\n', 1)354 status_line, headers = headers.split(b'\r\n', 1)355356 assert status_line == b'GET /path/to/thing/ HTTP/1.1'357 for frag in (b'view', b'edit', b'token', b'hunter2'):358 assert frag not in headers359 assert frag not in body360361 close_server.set()362Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 363why, one step back363Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 364–391why, one step back364def test_fragment_update_on_redirect():365 """Verify we only append previous fragment if one doesn't exist on new366 location. If a new fragment is encountered in a Location header, it should367 be added to all subsequent requests.368 """369370 def response_handler(sock):371 consume_socket_content(sock, timeout=0.5)372 sock.send(373 b'HTTP/1.1 302 FOUND\r\n'374 b'Content-Length: 0\r\n'375 b'Location: /get#relevant-section\r\n\r\n'376 )377 consume_socket_content(sock, timeout=0.5)378 sock.send(379 b'HTTP/1.1 302 FOUND\r\n'380 b'Content-Length: 0\r\n'381 b'Location: /final-url/\r\n\r\n'382 )383 consume_socket_content(sock, timeout=0.5)384 sock.send(385 b'HTTP/1.1 200 OK\r\n\r\n'386 )387388 close_server = threading.Event()389 server = Server(response_handler, wait_to_close_event=close_server)390391 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 392why, one step back392 url = f'http://{host}:{port}/path/to/thing/#view=edit&token=hunter2'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 393–399why, one step back393 r = requests.get(url)394395 assert r.status_code == 200396 assert len(r.history) == 2397 assert r.history[0].request.url == url398399 # Verify we haven't overwritten the location with our previous fragment.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 400why, one step back400 assert r.history[1].request.url == f'http://{host}:{port}/get#relevant-section'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
line 401why, one step back401 # Verify previous fragment is used and not the original.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 402why, one step back402 assert r.url == f'http://{host}:{port}/final-url/#relevant-section'Merge pull request #5594 from icfly2/patch-1Nate Prewittbefore adoption962c898
lines 403–404why, one step back403404 close_server.set()Fix inconsistent exception for JSONDecode error (#6097)Nate Prewittbefore adoption2d55176
line 405why, one step back405Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 406why, one step back406Fix inconsistent exception for JSONDecode error (#6097)Nate Prewittbefore adoption2d55176
lines 407–420why, one step back407def test_json_decode_compatibility_for_alt_utf_encodings():408409 def response_handler(sock):410 consume_socket_content(sock, timeout=0.5)411 sock.send(412 b'HTTP/1.1 200 OK\r\n'413 b'Content-Length: 18\r\n\r\n'414 b'\xff\xfe{\x00"\x00K0"\x00=\x00"\x00\xab0"\x00\r\n'415 )416417 close_server = threading.Event()418 server = Server(response_handler, wait_to_close_event=close_server)419420 with server as (host, port):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 421why, one step back421 url = f'http://{host}:{port}/'Fix inconsistent exception for JSONDecode error (#6097)Nate Prewittbefore adoption2d55176
lines 422–428why, one step back422 r = requests.get(url)423 r.encoding = None424 with pytest.raises(requests.exceptions.JSONDecodeError) as excinfo:425 r.json()426 assert isinstance(excinfo.value, requests.exceptions.RequestException)427 assert isinstance(excinfo.value, JSONDecodeError)428 assert r.text not in str(excinfo.value)