gdogg371
gdogg371

Reputation: 4122

AttributeError: 'module' object has no attribute 'Api'

I have written some basic Python code to try authenticate my credentials on twitter:

import twitter

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

But I receive the following error message when doing so:

Traceback (most recent call last):
  File "C:\Python33\nettest.py", line 3, in <module>
    api = twitter.Api(consumer_key='',
AttributeError: 'module' object has no attribute 'Api'

Can anyone see what I am doing wrong? I have tried variations on this code but they all seem to fall down with the api part of the twitter 1.14.2 that i am using. i have installed this module via pip 3.3 to my python 3.3 directory. when i look in lib>site_packages>twitter i can see that there is a module installed called api. I'm really not sure what is going wrong as this should seemingly be a simple piece of code to run.

Any ideas?

Upvotes: 3

Views: 10182

Answers (3)

infiniteloop
infiniteloop

Reputation: 1

Save your python file with any name other than twitter.py.

Upvotes: 0

Godwin
Godwin

Reputation: 51

  • simply uninstall twitter sudo pip uninstall twitter
  • Now install python-twiiter sudo pip install python-twitter... and it works..

Upvotes: 5

Carlos Ferreira
Carlos Ferreira

Reputation: 2078

If you were using the python-twitter You have a local file named twitter.py Rename it to twitterhelper.py or some other name and it should fix your problem. This was what fixed it for me.

Upvotes: 4

Related Questions