The python module module Twitter module does not have an Oauth attribute

I am trying to follow this basic example here .

Code

import twitter

# XXX: Go to http://dev.twitter.com/apps/new to create an app and get values
# for these credentials, which you'll need to provide in place of these
# empty string values that are defined as placeholders.
# See https://dev.twitter.com/docs/auth/oauth for more information 
# on Twitter OAuth implementation.

CONSUMER_KEY = ''
CONSUMER_SECRET =''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
                           CONSUMER_KEY, CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)

# Nothing to see by displaying twitter_api except that it now a
# defined variable

print twitter_api

But running the example causes the following error.

vagrant@lucid32:~$ python twitter.py
Traceback (most recent call last):
  File "twitter.py", line 1, in <module>
    import twitter
  File "/home/vagrant/twitter.py", line 14, in <module>
    auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
AttributeError: 'module' object has no attribute 'oauth'

Any help would be appreciated.

+4
source share
8 answers

You do not indicate which OS you are using. Is it Ubuntu or Debian?

If so, apt-get install python-twitterinstall the wrong package for your needs. Install the correct package as follows:

sudo apt-get purge python-twitter
sudo pip install twitter 

In addition, you must change the name of your program so that it is not identical to the imported module.

+3
source

, , , , python script, twitter.py twitter.

, - twitter.py, (twitter.pyc tweepy.pyc).

+3

. python-twitter. . python-twitter :

(!pip uninstall python-twitter)

Ipython twitter .

, .

+1

tweepy , , twitter

import tweepy
CONSUMER_KEY = ''
CONSUMER_SECRET =''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

api = tweepy.API(auth)
0

, , , , . -, , apt-get not pip, .

sudo apt-get purge python-twitter
sudo pip install twitter 
0

oauth2, oauth, python . , .

0

twitter.oauth.Oauth twitter.Api

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

0

I had the same problem and this is what helped me. At first I found out all the packages related to twitter, which in my case were tweepy and twitter . I removed both of them and installed twitter again. So far, so good. It worked for me.

help ("modules")

The main problem was not OAuth, but the installation of several Twitter packages.

0
source

All Articles