Skip to content
Myr

Merge pull request #1621 from davidfischer/migrate-2-0

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

Added migrating to 2.x docs

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 4401620, a17f559 · Browse files · 1 file+70 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+70 added−0 removed

  • other:+70 added−0 removed

1 file+70 added−0 removed

modified:docs/api.rst+70 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.204205For more details on the changes in this release including new APIs, links206to the relevant GitHub issues and some of the bug fixes, read Cory's blog_207on the subject.208209.. _blog: http://lukasa.co.uk/2013/09/Requests_20/210211212API Changes213~~~~~~~~~~~214215* There were a couple changes to how Requests handles exceptions.216 ``RequestException`` is now a subclass of ``IOError`` rather than217 ``RuntimeError`` as that more accurately categorizes the type of error.218 In addition, an invalid URL escape sequence now raises a subclass of219 ``RequestException`` rather than a ``ValueError``.220221 ::222223 requests.get('http://%zz/') # raises requests.exceptions.InvalidURL224225 Lastly, ``httplib.IncompleteRead`` exceptions caused by incorrect chunked226 encoding will now raise a Requests ``ChunkedEncodingError`` instead.227228* The proxy API has changed slightly. The scheme for a proxy URL is now229 required.230231 ::232233 proxies = {234 "http": "10.10.1.10:3128", # use http://10.10.1.10:3128 instead235 }236237 # In requests 1.x, this was legal, in requests 2.x,238 # this raises requests.exceptions.MissingSchema239 requests.get("http://example.org", proxies=proxies)240241242Behavioral Changes243~~~~~~~~~~~~~~~~~~244245* Keys in the ``headers`` dictionary are now native strings on all Python246 versions, i.e. bytestrings on Python 2 and unicode on Python 3. If the247 keys are not native strings (unicode on Python2 or bytestrings on Python 3)248 they will be converted to the native string type assuming UTF-8 encoding.249250* Timeouts behave slightly differently. On streaming requests, the timeout251 only applies to the connection attempt. On regular requests, the timeout252 is applied to the connection process and downloading the full body.253254 ::255256 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'257258 # One second timeout for the connection attempt259 # Unlimited time to download the tarball260 r = requests.get(tarball_url, stream=True, timeout=1)261262 # One second timeout for the connection attempt263 # Another full second timeout to download the tarball264 r = requests.get(tarball_url, timeout=1)265