Skip to content
Myr

Added migrating to 2.x docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Fischer · committed by David Fischer · parent 4401620 · Browse files · 1 file+64 added−0 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+64 added−0 removed

  • other:+64 added−0 removed

1 file+64 added−0 removed

modified:docs/api.rst+64 added
191 unmodified lines
192193.. _ISC: http://opensource.org/licenses/ISC194.. _Apache 2.0: http://opensource.org/licenses/Apache-2.0195196197Migrating to 2.x198----------------199200201Compared with the 1.0 release, there were relatively few backwards202incompatible changes, but there are still a few issues to be aware of with203this major release.204205206API Changes207~~~~~~~~~~~208209* There were a couple changes to how Requests handles exceptions.210 ``RequestException`` is now a subclass of ``IOError`` rather than211 ``RuntimeError`` as that more accurately categorizes the type of error.212 In addition, an invalid URL escape sequence now raises a subclass of213 ``RequestException`` rather than a ``ValueError``.214215 ::216217 requests.get('http://%zz/') # raises requests.exceptions.InvalidURL218219 Lastly, ``httplib.IncompleteRead`` exceptions caused by incorrect chunked220 encoding will now raise a Requests ``ChunkedEncodingError`` instead.221222* The proxy API has changed slightly. The scheme for a proxy URL is now223 required.224225 ::226227 proxies = {228 "http": "10.10.1.10:3128", # use http://10.10.1.10:3128 instead229 }230231 # In requests 1.x, this was legal, in requests 2.x,232 # this raises requests.exceptions.MissingSchema233 requests.get("http://example.org", proxies=proxies)234235236Behavioral Changes237~~~~~~~~~~~~~~~~~~238239* Keys in the ``headers`` dictionary are now native strings on all Python240 versions, i.e. bytestrings on Python 2 and unicode on Python 3. If the241 keys are not native strings (unicode on Python2 or bytestrings on Python 3)242 they will be converted to the native string type assuming UTF-8 encoding.243244* Timeouts behave slightly differently. On streaming requests, the timeout245 only applies to the connection attempt. On regular requests, the timeout246 is applied to the connection process and downloading the full body.247248 ::249250 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'251252 # One second timeout for the connection attempt253 # Unlimited time to download the tarball254 r = requests.get(tarball_url, stream=True, timeout=1)255256 # One second timeout for the connection attempt257 # Another full second timeout to download the tarball258 r = requests.get(tarball_url, timeout=1)259