Forums

Connecting to Twitter api - No module found

Trying to port a script that connects to Twitter. The credentials are stored within a local json file

import twitter

credentials = load_json("/home/username/.cred.json")
twitter_api = twitter.Api(consumer_key=credentials["consumer_key"],
                      consumer_secret=credentials["consumer_secret"],
                      access_token_key=credentials["access_token_key"],
                      access_token_secret=credentials["access_token_secret"],
                      tweet_mode='extended')

But get there error:

twitter_api = twitter.Api(consumer_key=credentials["consumer_key"], AttributeError: module 'twitter' has no attribute 'Api'

That might be a version incompatibility in the version of the twitter API you've written your code for, and the pre-installed version on PythonAnywhere. If you run "pip3.6 show twitter" on the machine where you developed it (replacing "3.6" with the version of Python you're using) then you can find out the version that you were using there, then you can install the same version on PythonAnywhere. For example, if it turned out that you were using 1.2.3 locally, the command (in a bash console) on PythonAnywhere would be

pip3.6 install --user twitter==1.2.3

...replacing the 3.6 with your preferred Python version again, of course.

Yes, it has been created using python-twitter. Is there a way to get access to python-twitter, using the following under a bash console "pip3.6 install twitter-python" give a permission denied response

See http://help.pythonanywhere.com/pages/InstallingNewModules/

Always read the instructions! Thanks for the assist

:-)