1

我正在尝试在 GAE 中使用 python-twitter api。我需要导入 Oauth2 和 httplib2。

这是我的做法

对于 OAuth2,我下载了 github.com/simplegeo/python-oauth2/tree/master/oauth2。对于 HTTPLib2,我下载了 code.google.com/p/httplib2/wiki/Install 并将文件夹 python2/httplib2 提取到项目根文件夹。

我的意见.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')

我收到错误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'

当我在 twitter.py 中跟踪错误时,我似乎没有正确导入 Oauth2

self._signature_method_plaintext = oauth.SignatureMethod_PLAINTEXT()

我什至去 twitter.py 并添加import oauth2 as oauth,但它无法解决问题

有人可以帮忙吗?

4

2 回答 2

1

我在我的 GAE 应用程序中使用了 tweetpy,它运行良好。 https://github.com/tweepy/tweepy

你可以在谷歌搜索中找到一些关于 GAE 的 tweetpy 示例代码。

于 2013-02-03T21:21:49.050 回答
1

我修好了它。在 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'

需要更改import oauthimport oauth2 as oauth

于 2013-02-03T13:14:27.240 回答