faq.rst
This file
Path
docs/community/faq.rst
89 lines · 3.4 KiB
Last changed by
Merge pull request #4996 from sblondon/masterKenneth Reitzbefore adoptionada5049
History of this fileTake it
1.. _faq:23Frequently Asked Questions4==========================56.. image:: https://farm5.staticflickr.com/4290/35294660055_42c02b2316_k_d.jpg78This part of the documentation answers common questions about Requests.910Encoded Data?11-------------1213Requests automatically decompresses gzip-encoded responses, and does14its best to decode response content to unicode when possible.1516You can get direct access to the raw response (and even the socket),17if needed as well.181920Custom User-Agents?21-------------------2223Requests allows you to easily override User-Agent strings, along with24any other HTTP Header. See `documentation about headers <http://docs.python-requests.org/en/master/user/quickstart/#custom-headers>`_.25262728Why not Httplib2?29-----------------3031Chris Adams gave an excellent summary on32`Hacker News <http://news.ycombinator.com/item?id=2884406>`_:3334 httplib2 is part of why you should use requests: it's far more respectable35 as a client but not as well documented and it still takes way too much code36 for basic operations. I appreciate what httplib2 is trying to do, that37 there's a ton of hard low-level annoyances in building a modern HTTP38 client, but really, just use requests instead. Kenneth Reitz is very39 motivated and he gets the degree to which simple things should be simple40 whereas httplib2 feels more like an academic exercise than something41 people should use to build production systems[1].4243 Disclosure: I'm listed in the requests AUTHORS file but can claim credit44 for, oh, about 0.0001% of the awesomeness.4546 1. http://code.google.com/p/httplib2/issues/detail?id=96 is a good example:47 an annoying bug which affect many people, there was a fix available for48 months, which worked great when I applied it in a fork and pounded a couple49 TB of data through it, but it took over a year to make it into trunk and50 even longer to make it onto PyPI where any other project which required "51 httplib2" would get the working version.525354Python 3 Support?55-----------------5657Yes! Here's a list of Python platforms that are officially58supported:5960* Python 2.761* Python 3.462* Python 3.563* Python 3.664* Python 3.765* PyPy6667What are "hostname doesn't match" errors?68-----------------------------------------6970These errors occur when :ref:`SSL certificate verification <verification>`71fails to match the certificate the server responds with to the hostname72Requests thinks it's contacting. If you're certain the server's SSL setup is73correct (for example, because you can visit the site with your browser) and74you're using Python 2.7, a possible explanation is that you need75Server-Name-Indication.7677`Server-Name-Indication`_, or SNI, is an official extension to SSL where the78client tells the server what hostname it is contacting. This is important79when servers are using `Virtual Hosting`_. When such servers are hosting80more than one SSL site they need to be able to return the appropriate81certificate based on the hostname the client is connecting to.8283Python3 and Python 2.7.9+ include native support for SNI in their SSL modules.84For information on using SNI with Requests on Python < 2.7.9 refer to this85`Stack Overflow answer`_.8687.. _`Server-Name-Indication`: https://en.wikipedia.org/wiki/Server_Name_Indication88.. _`virtual hosting`: https://en.wikipedia.org/wiki/Virtual_hosting89.. _`Stack Overflow answer`: https://stackoverflow.com/questions/18578439/using-requests-with-tls-doesnt-give-sni-support/18579484#18579484