[英]Connection refused to Twitter API on PythonAnywhere
I am trying to connect to the twitter streaming API on Python anywhere, but always get a connection refused error. 我试图在任何地方连接到Python上的Twitter流API,但总是得到连接拒绝错误。
I use Tweepy in my application, and to test the connection I am using the streaming example that can be found in the repo. 我在我的应用程序中使用Tweepy ,并测试连接我正在使用可以在repo中找到的流示例。
HEre is a sum-up of the code : HEre是代码的总结:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Go to http://dev.twitter.com and create an app.
# The consumer key and secret will be generated for you after
consumer_key=""
consumer_secret=""
# After the step above, you will be redirected to your app's page.
# Create an access token under the the "Your access token" section
access_token=""
access_token_secret=""
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['basketball'])
When I run this line in a bash console in python anywhere (after having filled the tokens of course) 当我在任何地方的python中的bash控制台中运行此行时(当然在填充了令牌之后)
12:02 ~/tweepy/examples (master)$ python streaming.py
I get the following error : 我收到以下错误:
Traceback (most recent call last):
File "streaming.py", line 33, in <module>
stream.filter(track=['basketball'])
File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 228, in filter
self._start(async)
File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 172, in _start
self._run()
File "/usr/local/lib/python2.7/site-packages/tweepy/streaming.py", line 106, in _run
conn.connect()
File "/usr/local/lib/python2.7/httplib.py", line 1157, in connect
self.timeout, self.source_address)
File "/usr/local/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
The domain .twitter.com is in the pythonanywhere whithelist though, so i don't understand why the connection would be refused :s. 域.twitter.com虽然在pythonanywhere whithelist,所以我不明白为什么连接会被拒绝:s。
The very same code works like a charm on my Ubuntu. 完全相同的代码就像我的Ubuntu上的魅力一样。
Any idea would be more than welcome, thanks !! 任何想法都会受到欢迎,谢谢!!
If you're using a Free account, tweepy won't work. 如果您使用的是免费帐户,则tweepy将无效。 It does not use the proxy settings from the environment.
它不使用环境中的代理设置。
There is a fork of tweepy that you might be able to use (http://github.com/ducu/tweepy) until the main line uses the proxy settings correctly. 在主线正确使用代理设置之前,您可以使用(http://github.com/ducu/tweepy)。
As Glenn said, there currently isn't proxy support in tweepy. 正如格伦所说,目前在tweepy中没有代理支持。
For a reason I cannot explain (and isn't documented), a pull request was closed without any merge about a month ago. 由于我无法解释(并且没有记录)的原因,拉动请求在一个月前没有任何合并被关闭。
https://github.com/tweepy/tweepy/pull/152 https://github.com/tweepy/tweepy/pull/152
There apparently is a fork available on github (see Glenn's answer), but I didn't test it. 显然github上有一个fork(参见Glenn的回答),但我没有测试它。
Knowing that I would need to use my own domain name in the end, I finally got a paid account on pythonanywhere and got rid of the proxy stuff all together. 知道我最终需要使用自己的域名,我终于在pythonanywhere上获得了一个付费帐户并且完全摆脱了代理的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.