Merge pull request #5128 from lmvlmv/urllibfix
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Use urllib for chunked requests
authored by Kenneth Reitz · committed by GitHub · parents 11ed88b, 989f702 · Browse files · 1 file·+13 added−58 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+13 added−58 removed
- other:+13 added−58 removed
Provenance
- Commit
42c5a4f- Tree
09c255e- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
GitHub <noreply@github.com>- Parent 1
11ed88b- Parent 2
989f702
1 file changed+13 added−58 removed
modified:requests/adapters.py+13 added-58 removed
433 unmodified lines434 else:435 timeout = TimeoutSauce(connect=timeout, read=timeout)436 437 try:438- if not chunked:439- resp = conn.urlopen(440- method=request.method,441- url=url,442- body=request.body,443- headers=request.headers,444- redirect=False,445- assert_same_host=False,446- preload_content=False,447- decode_content=False,448- retries=self.max_retries,449- timeout=timeout450- )438+ resp = conn.urlopen(439+ method=request.method,440+ url=url,441+ body=request.body,442+ headers=request.headers,443+ redirect=False,444+ assert_same_host=False,445+ preload_content=False,446+ decode_content=False,447+ retries=self.max_retries,448+ timeout=timeout,449+ chunked=chunked450+ )451 452- # Send the request.453- else:454- if hasattr(conn, 'proxy_pool'):455- conn = conn.proxy_pool456-457- low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)458-459- try:460- low_conn.putrequest(request.method,461- url,462- skip_accept_encoding=True)463-464- for header, value in request.headers.items():465- low_conn.putheader(header, value)466-467- low_conn.endheaders()468-469- for i in request.body:470- low_conn.send(hex(len(i))[2:].encode('utf-8'))471- low_conn.send(b'\r\n')472- low_conn.send(i)473- low_conn.send(b'\r\n')474- low_conn.send(b'0\r\n\r\n')475-476- # Receive the response from the server477- try:478- # For Python 2.7, use buffering of HTTP responses479- r = low_conn.getresponse(buffering=True)480- except TypeError:481- # For compatibility with Python 3.3+482- r = low_conn.getresponse()483-484- resp = HTTPResponse.from_httplib(485- r,486- pool=conn,487- connection=low_conn,488- preload_content=False,489- decode_content=False490- )491- except:492- # If we hit any problems here, clean up the connection.493- # Then, reraise so that we can handle the actual exception.494- low_conn.close()495- raise496-452 except (ProtocolError, socket.error) as err:453 raise ConnectionError(err, request=request)454 455 except MaxRetryError as e:33 unmodified lines