Question

I have installed Python 2.7 and trying to use Twitter package. I have installed the 3 pre-requisite packages successfully... But somehow getting this error:

>>> import twitter
>>> api = twitter.Api()
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    api = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'

The I tried this version but got the same error:

>>> api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',
                  access_token_key='access_token',
                  access_token_secret='access_token_secret')

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    api = twitter.Api(consumer_key='consumer_key',
AttributeError: 'module' object has no attribute 'Api'

I have installed 3 packages for twitter namely: python-twitter-0.8.5, python-twitter-1.0, twitter-1.10.0

and the output of the command is as below:

>>> twitter.__file__
'C:\\Python27\\lib\\site-packages\\twitter-1.10.0-py2.7.egg\\twitter\\__init__.pyc'

Should I be uninstalling something? I have renamed twitter.py files in python-twitter-0.8.5 and python-twitter-1.0 but still getting the error...

Was it helpful?

Solution

You installed a different Twitter API module; you installed twitter 1.10.0, not python-twitter. The APIs between the two projects differ significantly:

import twitter

t = twitter.Twitter(
        auth=twitter.OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                   CONSUMER_KEY, CONSUMER_SECRET)
       )

You may want to uninstall twitter and install python-twitter instead.

However, if all you need is a good Twitter API package for Python, take a look at the list that Twitter maintains. Tweepy and a different python-twitter package are under active maintenance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top