Problem with using Twitter related modules

Problem with using Twitter related modules

Postby gdogg371 » Wed Apr 02, 2014 4:22 pm

I am fairly new to Python and I have the following piece of Python code that I am struggling to get to work and I'm not sure why:

Code: Select all
import simplejson
import oauth
import twitter
import oauthtwitter

from oauthtwitter import OAuthApi
 
class OauthRequest():
    CONSUMER_KEY = "XXXXXXXXXXXXXXXXXX"
    CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    AUTHORIZATION_URL = 'http://twitter.com/oauth/authorize'
    REQUEST_TOKEN_URL = 'https://twitter.com/oauth/request_token'
 
    def GetRequest(self):
        vOauthApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET)
        self.mOauthRequestToken = vOauthApi.getRequestToken(self.REQUEST_TOKEN_URL)
        self.mOauthRequestUrl = vOauthApi.getAuthorizationURL(self.mOauthRequestToken)


This has been taken from this website:

http://popdevelop.com/2010/07/an-example-on-how-to-use-oauth-and-python-to-connect-to-twitter/

I am using the modules 'oauth 1.0.1', 'oauth-python-twitter 1.0' and 'twitter 1.14.2'. These have been installed to Python 3.3 using Pip. There no longer seems to be a standard package called 'twitter.py' like the one used in the above link, but I am presuming that 'twitter 1.14.2' is an evolution of that.

When I run the code I get the following error:

Code: Select all
Traceback (most recent call last):
  File "C:\Python33\nettest.py", line 4, in <module>
    import oauthtwitter
  File "C:\Python33\lib\site-packages\oauthtwitter.py", line 17, in <module>
    from twitter import Api, User
ImportError: cannot import name Api


I understand that the error itself is being generated because the oauthtwitter module is trying to reference something within the 'twitter' module called 'api' that it cant find, however I can see than an API module of the twitter package has been installed.

Can anyone see what is going wrong here?

Thanks
Last edited by stranac on Wed Apr 02, 2014 4:29 pm, edited 1 time in total.
Reason: First post lock.
gdogg371
 
Posts: 2
Joined: Wed Apr 02, 2014 4:15 pm

Re: Problem with using Twitter related modules

Postby micseydel » Wed Apr 02, 2014 5:37 pm

Do you have your own file named twitter.py? If so, renaming the file will probably solve your problem.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1435
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Problem with using Twitter related modules

Postby gdogg371 » Wed Apr 02, 2014 5:46 pm

no i dont. i did have, but i renamed it to see if that was the issue. alas it was not.
gdogg371
 
Posts: 2
Joined: Wed Apr 02, 2014 4:15 pm

Re: Problem with using Twitter related modules

Postby micseydel » Wed Apr 02, 2014 7:54 pm

Do you still have a twitter.pyc file there? What is the output from this code?
Code: Select all
import twitter
print twitter
.__file__
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1435
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Web Development

Who is online

Users browsing this forum: No registered users and 2 guests