Proxy Object

33 views
Skip to first unread message

Pierrot

unread,
May 17, 2012, 4:39:49 AM5/17/12
to Twython Talk

> Alright, I committed some work that should hopefully take care of your
> Proxy woes.
> http://github.com/ryanmcgrath/twython/commit/f82702e70643621c0a82ed74...
> Basically, pass an object like the following to the setup method. I've
> not been able to test this thoroughly yet, so any tests you can do
> would be appreciated. Feel free to file bugs on the Github project.

> import twython
> proxyobj = {
> "username": "fjnfsjdnfjd",
> "password": "fjnfjsjdfnjd",
> "host": "http://fjanfjasnfjjfnajsdfasd.com",
> "port": 87
>}
> lol = twython.setup("username", "password", proxy = proxyobj)


>>> import twython
>>> proxyobj = {
... "username": "fjnfsjdnfjd",
... "password": "fjnfjsjdfnjd",
... "host": "http://fjanfjasnfjjfnajsdfasd.com",
... "port": 87
...
... }
>>>
>>> lol = twython.setup("username", "password", proxy = proxyobj)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setup'

I'm very interested by this feature. I have tried to test with the
last version of twython,
but I got no setup attributes. Is there another way to set a proxy
programmatically
for the Oauth API (not the streaming)?

Ryan McGrath

unread,
May 17, 2012, 5:00:25 AM5/17/12
to Twython Talk
Hey there,

This was actually deprecated (for why... I can't recall...) in the
move to OAuth support. There's been interest in bringing it back
though - feel free to fork/patch on GitHub and such, otherwise it's on
the todo-list. :)

- Ryan

pierre baral

unread,
May 17, 2012, 5:18:44 AM5/17/12
to twytho...@googlegroups.com
Thanks for your answer Ryan!

2012/5/17 Ryan McGrath <ryan.m...@gmail.com>

Pierrot

unread,
May 17, 2012, 9:36:37 AM5/17/12
to Twython Talk
I have checked your code to see how to implement it.

It seems you use the requests module! I did not know that module.
After having checked their documentation:
http://docs.python-requests.org/en/latest/user/advanced/#proxies

I would add/store a proxy dictionnary in the __init__() (ex:
self.proxy)
then in the _request() method, I would add proxies=self.proxy in
func().

I'm not sure if it works, or it's the best implementation but I will
try.

Btw I hope OAuth1 does not connect somewhere on the net and
just generate a hash or something secret with oauth_secret*/tokens*?

On 17 mai, 11:18, pierre baral <pierre.ba...@gmail.com> wrote:
> Thanks for your answer Ryan!
>
> 2012/5/17 Ryan McGrath <ryan.mcgra...@gmail.com>

Pierrot

unread,
May 17, 2012, 10:12:02 AM5/17/12
to Twython Talk
Ok works fine for me with 2 shorts modifications!
I will send something cleaner maybe later if someone is interested! :)

You just need to a add a dict attribute to the Twython class.
Then to call func() with proxies=self.proxies.
You also need to catch exceptions from func() ...
(requests.exceptions.ConnectionError are thrown with bad proxies)

that's all :-)
Reply all
Reply to author
Forward
0 new messages