Skip to content

Commit 0bc8775

Browse files
committed
updated module requests
1 parent 2b6a1ae commit 0bc8775

File tree

19 files changed

+302
-118
lines changed

19 files changed

+302
-118
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14.3.3
1+
14.4.4

changelog.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ Version 14.3.2 BETA
1010
- made code PEP8 compliant
1111

1212
Version 14.3.3 BETA
13-
- dropped own logging, now using python built in logging function (you might delete the file logger.py if existant)
14-
- created file miniprobe.py which offers base functionality, probe.py now only does the work
15-
- various changes and code cleanup
16-
- added script templates for the probe_installer.py in folder /scripts
13+
- [major] dropped own logging, now using python built in logging function (you might delete the file logger.py if existant)
14+
- [major] created file miniprobe.py which offers base functionality, probe.py now only does the work
15+
- [minor] various changes and code cleanup
16+
- [minor] added script templates for the probe_installer.py in folder /scripts
17+
18+
Version 14.4.4 BETA
19+
- [minor] Updated module requests to ver 2.3.4 which also includes a new version of urllib3
1720

requests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
usage:
1414
1515
>>> import requests
16-
>>> r = requests.get('http://python.org')
16+
>>> r = requests.get('https://www.python.org')
1717
>>> r.status_code
1818
200
1919
>>> 'Python is a programming language' in r.content
@@ -22,7 +22,7 @@
2222
... or POST:
2323
2424
>>> payload = dict(key1='value1', key2='value2')
25-
>>> r = requests.post("http://httpbin.org/post", data=payload)
25+
>>> r = requests.post('http://httpbin.org/post', data=payload)
2626
>>> print(r.text)
2727
{
2828
...
@@ -42,8 +42,8 @@
4242
"""
4343

4444
__title__ = 'requests'
45-
__version__ = '2.3.0'
46-
__build__ = 0x020300
45+
__version__ = '2.4.3'
46+
__build__ = 0x020403
4747
__author__ = 'Kenneth Reitz'
4848
__license__ = 'Apache 2.0'
4949
__copyright__ = 'Copyright 2014 Kenneth Reitz'

requests/adapters.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
from .packages.urllib3.poolmanager import PoolManager, proxy_from_url
1616
from .packages.urllib3.response import HTTPResponse
1717
from .packages.urllib3.util import Timeout as TimeoutSauce
18-
from .compat import urlparse, basestring, urldefrag, unquote
18+
from .compat import urlparse, basestring
1919
from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
20-
prepend_scheme_if_needed, get_auth_from_url)
20+
prepend_scheme_if_needed, get_auth_from_url, urldefragauth)
2121
from .structures import CaseInsensitiveDict
22-
from .packages.urllib3.exceptions import MaxRetryError
23-
from .packages.urllib3.exceptions import TimeoutError
24-
from .packages.urllib3.exceptions import SSLError as _SSLError
22+
from .packages.urllib3.exceptions import ConnectTimeoutError
2523
from .packages.urllib3.exceptions import HTTPError as _HTTPError
24+
from .packages.urllib3.exceptions import MaxRetryError
2625
from .packages.urllib3.exceptions import ProxyError as _ProxyError
26+
from .packages.urllib3.exceptions import ProtocolError
27+
from .packages.urllib3.exceptions import ReadTimeoutError
28+
from .packages.urllib3.exceptions import SSLError as _SSLError
2729
from .cookies import extract_cookies_to_jar
28-
from .exceptions import ConnectionError, Timeout, SSLError, ProxyError
30+
from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,
31+
ProxyError)
2932
from .auth import _basic_auth_str
3033

3134
DEFAULT_POOLBLOCK = False
@@ -267,7 +270,7 @@ def request_url(self, request, proxies):
267270
proxy = proxies.get(scheme)
268271

269272
if proxy and scheme != 'https':
270-
url, _ = urldefrag(request.url)
273+
url = urldefragauth(request.url)
271274
else:
272275
url = request.path_url
273276

@@ -314,7 +317,10 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
314317
315318
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
316319
:param stream: (optional) Whether to stream the request content.
317-
:param timeout: (optional) The timeout on the request.
320+
:param timeout: (optional) How long to wait for the server to send
321+
data before giving up, as a float, or a (`connect timeout, read
322+
timeout <user/advanced.html#timeouts>`_) tuple.
323+
:type timeout: float or tuple
318324
:param verify: (optional) Whether to verify SSL certificates.
319325
:param cert: (optional) Any user-provided SSL certificate to be trusted.
320326
:param proxies: (optional) The proxies dictionary to apply to the request.
@@ -328,7 +334,18 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
328334

329335
chunked = not (request.body is None or 'Content-Length' in request.headers)
330336

331-
timeout = TimeoutSauce(connect=timeout, read=timeout)
337+
if isinstance(timeout, tuple):
338+
try:
339+
connect, read = timeout
340+
timeout = TimeoutSauce(connect=connect, read=read)
341+
except ValueError as e:
342+
# this may raise a string formatting error.
343+
err = ("Invalid timeout {0}. Pass a (connect, read) "
344+
"timeout tuple, or a single float to set "
345+
"both timeouts to the same value".format(timeout))
346+
raise ValueError(err)
347+
else:
348+
timeout = TimeoutSauce(connect=timeout, read=timeout)
332349

333350
try:
334351
if not chunked:
@@ -386,10 +403,13 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
386403
# All is well, return the connection to the pool.
387404
conn._put_conn(low_conn)
388405

389-
except socket.error as sockerr:
390-
raise ConnectionError(sockerr, request=request)
406+
except (ProtocolError, socket.error) as err:
407+
raise ConnectionError(err, request=request)
391408

392409
except MaxRetryError as e:
410+
if isinstance(e.reason, ConnectTimeoutError):
411+
raise ConnectTimeout(e, request=request)
412+
393413
raise ConnectionError(e, request=request)
394414

395415
except _ProxyError as e:
@@ -398,8 +418,8 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
398418
except (_SSLError, _HTTPError) as e:
399419
if isinstance(e, _SSLError):
400420
raise SSLError(e, request=request)
401-
elif isinstance(e, TimeoutError):
402-
raise Timeout(e, request=request)
421+
elif isinstance(e, ReadTimeoutError):
422+
raise ReadTimeout(e, request=request)
403423
else:
404424
raise
405425

requests/api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ def request(method, url, **kwargs):
2222
:param url: URL for the new :class:`Request` object.
2323
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
2424
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
25+
:param json: (optional) json data to send in the body of the :class:`Request`.
2526
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
2627
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
27-
:param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.
28+
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': ('filename', fileobj)}``) for multipart encoding upload.
2829
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
29-
:param timeout: (optional) Float describing the timeout of the request in seconds.
30+
:param timeout: (optional) How long to wait for the server to send data
31+
before giving up, as a float, or a (`connect timeout, read timeout
32+
<user/advanced.html#timeouts>`_) tuple.
33+
:type timeout: float or tuple
3034
:param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
35+
:type allow_redirects: bool
3136
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
3237
:param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.
3338
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
@@ -77,15 +82,16 @@ def head(url, **kwargs):
7782
return request('head', url, **kwargs)
7883

7984

80-
def post(url, data=None, **kwargs):
85+
def post(url, data=None, json=None, **kwargs):
8186
"""Sends a POST request. Returns :class:`Response` object.
8287
8388
:param url: URL for the new :class:`Request` object.
8489
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
90+
:param json: (optional) json data to send in the body of the :class:`Request`.
8591
:param \*\*kwargs: Optional arguments that ``request`` takes.
8692
"""
8793

88-
return request('post', url, data=data, **kwargs)
94+
return request('post', url, data=data, json=json, **kwargs)
8995

9096

9197
def put(url, data=None, **kwargs):

requests/auth.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .compat import urlparse, str
1818
from .cookies import extract_cookies_to_jar
1919
from .utils import parse_dict_header, to_native_string
20+
from .status_codes import codes
2021

2122
CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
2223
CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
@@ -150,6 +151,11 @@ def sha_utf8(x):
150151

151152
return 'Digest %s' % (base)
152153

154+
def handle_redirect(self, r, **kwargs):
155+
"""Reset num_401_calls counter on redirects."""
156+
if r.is_redirect:
157+
setattr(self, 'num_401_calls', 1)
158+
153159
def handle_401(self, r, **kwargs):
154160
"""Takes the given response and tries digest-auth, if needed."""
155161

@@ -182,7 +188,7 @@ def handle_401(self, r, **kwargs):
182188

183189
return _r
184190

185-
setattr(self, 'num_401_calls', 1)
191+
setattr(self, 'num_401_calls', num_401_calls + 1)
186192
return r
187193

188194
def __call__(self, r):
@@ -194,4 +200,5 @@ def __call__(self, r):
194200
except AttributeError:
195201
pass
196202
r.register_hook('response', self.handle_401)
203+
r.register_hook('response', self.handle_redirect)
197204
return r

requests/exceptions.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,23 @@ class SSLError(ConnectionError):
4444

4545

4646
class Timeout(RequestException):
47-
"""The request timed out."""
47+
"""The request timed out.
48+
49+
Catching this error will catch both
50+
:exc:`~requests.exceptions.ConnectTimeout` and
51+
:exc:`~requests.exceptions.ReadTimeout` errors.
52+
"""
53+
54+
55+
class ConnectTimeout(ConnectionError, Timeout):
56+
"""The request timed out while trying to connect to the remote server.
57+
58+
Requests that produced this error are safe to retry.
59+
"""
60+
61+
62+
class ReadTimeout(Timeout):
63+
"""The server did not send any data in the allotted amount of time."""
4864

4965

5066
class URLRequired(RequestException):
@@ -73,3 +89,6 @@ class ChunkedEncodingError(RequestException):
7389

7490
class ContentDecodingError(RequestException, BaseHTTPError):
7591
"""Failed to decode response content"""
92+
93+
class StreamConsumedError(RequestException, TypeError):
94+
"""The content for this response was already consumed"""

0 commit comments

Comments
 (0)