Search code examples
pythontwitteroauth

module object has no attribute oauth


I am trying to use the twitter library to pull some tweets but I am unable to get my authorization correctly. This is my code

import twitter
consumer_key = ''
consumer_secret = ''
access_token = '' 
access_secret = ''
t = Twitter( auth = OAuth(access_token, access_secret, consumer_key, consumer_secret))
api = twitter.Twitter( auth = auth )
print api

It is throwing AttributeError:'module' object has no attribute 'oauth'. I am simply pasting code from twitter help but then why is it not working?


Solution

  • Without knowing which library you are using I'm going to assume you are using this one because the syntax looks the same. The error being thrown suggests that you are not importing the module that handles oauth. You could import all modules by adding this to the top of your code:

    from twitter import *
    

    This isn't really recommended because you might not need every module in the library so just import the ones you need e.g.:

    from twitter import oauth