From 1844818138e32aeb64a3f0b307f14e8b2679d344 Mon Sep 17 00:00:00 2001 From: Erik Dominguez Date: Sat, 29 Aug 2015 11:07:32 -0700 Subject: [PATCH] User-Agent and Proxy docs with the best I can pep8 Some use-cases for adding a custom User-Agent and proxies for use in your API with Pep8 compatible examples. --- docs/options.rst | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/docs/options.rst b/docs/options.rst index 713ab0d..e0fb454 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -64,6 +64,39 @@ Turning SSL certificate verification off:: API("https://path/to/my/api", session=requests.Session(verify=False)) + +User-Agent +---------------- + +Adding a different User-Agent:: + + user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " \ + "(KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36" + + #Also, additional headers can be passed through + #the headers parameter when construction the Session object + headers = {'User-Agent':user_agent} + API("https://path/to/mdy/api", + session=requests.Session(headers=headers)) + +Proxies +---------------- + +Using http(s) proxies:: + + #You need a http and https proxy. If its the same proxy, then use + # the same proxy for http and https. + proxies = {'http':'http://111.111.111.111:8080', + 'https':'http://111.111.111.111:8080'} + + headers = {'User-Agent':user_agent} + #proxies with username and password + authenticated_prxoies = {'http':'http://user:password@111.111.111.111:8080', + 'https':'http://user:password@111.111.111.111:8080'} + API("https://path/to/my/api", + session=requests.Session(headers=headers)) + + For more information see the documentation for ``requests.Session``. File uploads