1

I am trying to use python-twitter api in GAE. I need to import Oauth2 and httplib2.

Here is how I did

For OAuth2, I downloaded github.com/simplegeo/python-oauth2/tree/master/oauth2. For HTTPLib2, I dowloaded code.google.com/p/httplib2/wiki/Install and extracted folder python2/httplib2 to project root folder.

my views.py

import twitter


def index(request):
  api = twitter.Api(consumer_key='XNAUYmsmono4gs3LP4T6Pw',consumer_secret='xxxxx',access_token_key='xxxxx',access_token_secret='iHzMkC6RRDipon1kYQtE5QOAYa1bVfYMhH7GFmMFjg',cache=None)


  return render_to_response('fbtwitter/index.html')

I got the error paste.shehas.net/show/jbXyx2MSJrpjt7LR2Ksc

AttributeError

AttributeError: 'module' object has no attribute 'SignatureMethod_PLAINTEXT'
Traceback (most recent call last)

    File "D:\PythonProj\fbtwitter\kay\lib\werkzeug\wsgi.py", line 471, in __call__

    return app(environ, start_response)

    File "D:\PythonProj\fbtwitter\kay\app.py", line 478, in __call__

    response = self.get_response(request)

    File "D:\PythonProj\fbtwitter\kay\app.py", line 405, in get_response

    return self.handle_uncaught_exception(request, exc_info)

    File "D:\PythonProj\fbtwitter\kay\app.py", line 371, in get_response

    response = view_func(request, **values)

    File "D:\PythonProj\fbtwitter\fbtwitter\views.py", line 39, in index

    access_token_secret='iHzMkC6RRDipon1kYQtE5QOAYa1bVfYMhH7GFmMFjg',cache=None)

    File "D:\PythonProj\fbtwitter\fbtwitter\twitter.py", line 2235, in __init__

    self.SetCredentials(consumer_key, consumer_secret, access_token_key, access_token_secret)

    File "D:\PythonProj\fbtwitter\fbtwitter\twitter.py", line 2264, in SetCredentials

    self._signature_method_plaintext = oauth.SignatureMethod_PLAINTEXT()

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

It seems I did not import Oauth2 correctly when I tracked the error in twitter.py

self._signature_method_plaintext = oauth.SignatureMethod_PLAINTEXT()

I even go to twitter.py and add import oauth2 as oauth but it couldnt solve the problem

Can anybody help?

John
  • 3,888
  • 11
  • 46
  • 84

2 Answers2

1

I fixed it. In twitter.py,

try:
  from hashlib import md5
except ImportError:
  from md5 import md5

import oauth


CHARACTER_LIMIT = 140

# A singleton representing a lazily instantiated FileCache.
DEFAULT_CACHE = object()

REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
ACCESS_TOKEN_URL  = 'https://api.twitter.com/oauth/access_token'
AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
SIGNIN_URL        = 'https://api.twitter.com/oauth/authenticate'

Need to change import oauth to import oauth2 as oauth

John
  • 3,888
  • 11
  • 46
  • 84
1

I'm using tweetpy with my GAE application and it works well. https://github.com/tweepy/tweepy

You can find some sample codes of tweetpy on GAE in google search.

yosuke
  • 157
  • 6