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 をプロジェクトのルート フォルダーに抽出しました。

私の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')

エラーが発生した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

それを私が直した。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 oauthする必要がありますimport oauth2 as oauth

于 2013-02-03T13:14:27.240 に答える
1

私は GAE アプリケーションで tweetpy を使用していますが、うまく動作します。 https://github.com/teepy/tweepy

Google 検索で GAE の tweetpy のサンプル コードを見つけることができます。

于 2013-02-03T21:21:49.050 に答える