Skip to content

Commit 25cfd09

Browse files
Update docs to give examples for manipulating requests args
1 parent a0aae46 commit 25cfd09

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

docs/usage/advanced_usage.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,66 @@ That being said, Twython offers a generator for search results and can be access
4040
for result in search:
4141
print result
4242

43+
Manipulate the Request (headers, proxies, etc.)
44+
-----------------------------------------------
45+
46+
There are times when you may want to turn SSL verification off, send custom headers, or add proxies for the request to go through.
47+
48+
Twython uses the `requests <http://python-requests.org>`_ library to make API calls to Twitter. ``requests`` accepts a few parameters to allow developers to manipulate the acutal HTTP request.
49+
50+
Here is an example of sending custom headers to a Twitter API request:
51+
52+
::
53+
54+
from twython import Twython
55+
56+
client_args = {
57+
'headers': {
58+
'User-Agent': 'My App Name'
59+
}
60+
}
61+
62+
twitter = Twython(APP_KEY, APP_SECRET
63+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
64+
client_args=client_args)
65+
66+
Here is an example of sending the request through proxies:
67+
68+
::
69+
70+
from twython import Twython
71+
72+
client_args = {
73+
'proxies': {
74+
'http': '10.0.10.1:8000',
75+
'https': '10.0.10.1:8001',
76+
}
77+
}
78+
79+
twitter = Twython(APP_KEY, APP_SECRET
80+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
81+
client_args=client_args)
82+
83+
or both (and set a timeout variable):
84+
85+
::
86+
87+
from twython import Twython
88+
89+
client_args = {
90+
'headers': {
91+
'User-Agent': 'My App Name'
92+
},
93+
'proxies': {
94+
'http': '10.0.10.1:8000',
95+
'https': '10.0.10.1:8001',
96+
}
97+
'timeout': 300,
98+
}
99+
100+
twitter = Twython(APP_KEY, APP_SECRET
101+
OAUTH_TOKEN, OAUTH_TOKEN_SECRET
102+
client_args=client_args)
103+
43104

44105
So now you can authenticate, update your status (with or without an image), search Twitter, and a few other things! Good luck!

0 commit comments

Comments
 (0)