Accessing twitter using tornado.httpclient using proxy [closed]

筅森魡賤 提交于 2019-12-11 03:58:15

问题


I want to access Twitter from the terminal using tornado.httpcilent.

But Twitter is firewalled in my country. How can I access it through proxy?

Are there any other options?


回答1:


The official documentation for tornado.httpclient contains examples how to use proxy.

You will need curl backend for proxy support. So install the prerequisites. Here's how to do that for Ubuntu:

$ sudo apt-get install libcurl-dev librtmp-dev 
$ pip install tornado pycurl

Then try this code:

from tornado import httpclient, ioloop

config = {
    'proxy_host': 'YOUR_PROXY_HOSTNAME_OR_IP_ADDRESS',
    'proxy_port': 3128
}

httpclient.AsyncHTTPClient.configure(
    "tornado.curl_httpclient.CurlAsyncHTTPClient")

def handle_request(response):
    if response.error:
        print "Error:", response.error
    else:
        print response.body
    ioloop.IOLoop.instance().stop()

http_client = httpclient.AsyncHTTPClient()
http_client.fetch("http://twitter.com/",
    handle_request, **config)
ioloop.IOLoop.instance().start()


来源:https://stackoverflow.com/questions/12016951/accessing-twitter-using-tornado-httpclient-using-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!