| 1 |
.. _faq: |
| 2 |
|
| 3 |
Frequently Asked Questions |
| 4 |
========================== |
| 5 |
|
| 6 |
This part of the documentation answers common questions about Requests. |
| 7 |
|
| 8 |
Encoded Data? |
| 9 |
------------- |
| 10 |
|
| 11 |
Requests automatically decompresses gzip-encoded responses, and does |
| 12 |
its best to decode response content to unicode when possible. |
| 13 |
|
| 14 |
When either the `brotli <https://pypi.org/project/Brotli/>`_ or `brotlicffi <https://pypi.org/project/brotlicffi/>`_ |
| 15 |
package is installed, requests also decodes Brotli-encoded responses. |
| 16 |
|
| 17 |
You can get direct access to the raw response (and even the socket), |
| 18 |
if needed as well. |
| 19 |
|
| 20 |
|
| 21 |
Custom User-Agents? |
| 22 |
------------------- |
| 23 |
|
| 24 |
Requests allows you to easily override User-Agent strings, along with |
| 25 |
any other HTTP Header. See :ref:`documentation about headers <custom-headers>`. |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
Why not Httplib2? |
| 30 |
----------------- |
| 31 |
|
| 32 |
Chris Adams gave an excellent summary on |
| 33 |
`Hacker News <https://news.ycombinator.com/item?id=2884406>`_: |
| 34 |
|
| 35 |
httplib2 is part of why you should use requests: it's far more respectable |
| 36 |
as a client but not as well documented and it still takes way too much code |
| 37 |
for basic operations. I appreciate what httplib2 is trying to do, that |
| 38 |
there's a ton of hard low-level annoyances in building a modern HTTP |
| 39 |
client, but really, just use requests instead. Kenneth Reitz is very |
| 40 |
motivated and he gets the degree to which simple things should be simple |
| 41 |
whereas httplib2 feels more like an academic exercise than something |
| 42 |
people should use to build production systems[1]. |
| 43 |
|
| 44 |
Disclosure: I'm listed in the requests AUTHORS file but can claim credit |
| 45 |
for, oh, about 0.0001% of the awesomeness. |
| 46 |
|
| 47 |
1. https://code.google.com/p/httplib2/issues/detail?id=96 is a good example: |
| 48 |
an annoying bug that affected many people, there was a fix available for |
| 49 |
months, which worked great when I applied it in a fork and pounded a couple |
| 50 |
TB of data through it, but it took over a year to make it into trunk and |
| 51 |
even longer to make it onto PyPI where any other project which required " |
| 52 |
httplib2" would get the working version. |
| 53 |
|
| 54 |
|
| 55 |
Python 3 Support? |
| 56 |
----------------- |
| 57 |
|
| 58 |
Yes! Requests supports all `officially supported versions of Python <https://devguide.python.org/versions/>`_ |
| 59 |
and recent releases of PyPy. |
| 60 |
|
| 61 |
Python 2 Support? |
| 62 |
----------------- |
| 63 |
|
| 64 |
No! As of Requests 2.28.0, Requests no longer supports Python 2.7. Users who |
| 65 |
have been unable to migrate should pin to `requests<2.28`. Full information |
| 66 |
can be found in `psf/requests#6023 <https://github.com/psf/requests/issues/6023>`_. |
| 67 |
|
| 68 |
It is *highly* recommended users migrate to a supported Python 3.x version now since |
| 69 |
Python 2.7 is no longer receiving bug fixes or security updates as of January 1, 2020. |
| 70 |
|
| 71 |
What are "hostname doesn't match" errors? |
| 72 |
----------------------------------------- |
| 73 |
|
| 74 |
These errors occur when :ref:`SSL certificate verification <verification>` |
| 75 |
fails to match the certificate the server responds with to the hostname |
| 76 |
Requests thinks it's contacting. If you're certain the server's SSL setup is |
| 77 |
correct (for example, because you can visit the site with your browser) and |
| 78 |
you're using Python 2.7, a possible explanation is that you need |
| 79 |
Server-Name-Indication. |
| 80 |
|
| 81 |
`Server-Name-Indication`_, or SNI, is an official extension to SSL where the |
| 82 |
client tells the server what hostname it is contacting. This is important |
| 83 |
when servers are using `Virtual Hosting`_. When such servers are hosting |
| 84 |
more than one SSL site they need to be able to return the appropriate |
| 85 |
certificate based on the hostname the client is connecting to. |
| 86 |
|
| 87 |
Python 3 already includes native support for SNI in their SSL modules. |
| 88 |
|
| 89 |
.. _`Server-Name-Indication`: https://en.wikipedia.org/wiki/Server_Name_Indication |
| 90 |
.. _`virtual hosting`: https://en.wikipedia.org/wiki/Virtual_hosting |