Connection dropped the Twitter API on PythonAnywhere

I am trying to connect to twitter twitter streaming API in Python anywhere, but I always get the connection refused.

I am using Tweepy in my application, and I am using the streaming example found in the repo to test the connection.

HEre is the sum of the code:

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 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 bash console in python anywhere (after filling in the markers of course)

12:02 ~/tweepy/examples (master)$ python streaming.py 

      

I am getting 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, so I don't understand why the connection would be denied: s.

The same code works like a charm on my Ubuntu.

Any idea would be more than welcomed, thanks!

+3


source to share


2 answers


If you are using a free account, tweepy will not work. It does not use proxy settings from the environment.



There is a fork of tweepy you could use (http://github.com/ducu/tweepy) until the main line is using proxy settings correctly.

+6


source


As Glenn said, there is currently no proxy support in tweepy.

For some reason I cannot explain (and is not documented) the pull request was closed without any merge about a month ago.

https://github.com/tweepy/tweepy/pull/152



There appears to be a fork available on github (see Glenn's answer), but I haven't tested it.

Knowing that I would eventually need to use my own domain name, I finally got a paid pythonanywhere account and got rid of the proxy entirely.

+2


source







All Articles