首页 > 解决方案 > GAE:失败:只有 tempfile.TemporaryFile 可供使用

问题描述

我正在尝试在 Flask 上验证 twitter 登录。

if flask.request.args.get('oauth_verifier')==None: 
    twauth = tweepy.OAuthHandler("***","***")
    twauth.secure = True
    try:
      redirect_url = twauth.get_authorization_url() #This call requests the token from twitter and returns to us the authorization URL
    except tweepy.TweepError,e:
      logging.info('Failed : %s' % e)
      print redirect_url
    flask.session['request_token'] = twauth.request_token  #storing the request token in a session:

twauth.get_authorization_url()在下面创建错误

2018-06-13 16:50:48.047 JST
Fetching token from https://api.twitter.com/oauth/request_token using client <Client nonce=None, signature_method=HMAC-SHA1, realm=None, encoding=utf-8, timestamp=None, resource_owner_secret=None, decoding=utf-8, verifier=None, signature_type=AUTH_HEADER, rsa_key=None, resource_owner_key=None, client_secret=****, callback_uri=None, client_key=gpQh2S0rWdIdTCHfoaA3q2KYL> (lib.zip/requests_oauthlib/oauth1_session.py:363)
2018-06-13 16:50:48.048 JST
Signing request <PreparedRequest [POST]> using client <Client nonce=None, signature_method=HMAC-SHA1, realm=None, encoding=utf-8, timestamp=None, resource_owner_secret=None, decoding=utf-8, verifier=None, signature_type=AUTH_HEADER, rsa_key=None, resource_owner_key=None, client_secret=****, callback_uri=None, client_key=gpQh2S0rWdIdTCHfoaA3q2KYL> (lib.zip/requests_oauthlib/oauth1_auth.py:63)
2018-06-13 16:50:48.048 JST
Including body in call to sign: False (lib.zip/requests_oauthlib/oauth1_auth.py:75)
2018-06-13 16:50:48.048 JST
Collected params: [(u'oauth_version', u'1.0'), (u'oauth_consumer_key', u'gpQh2S0rWdIdTCHfoaA3q2KYL'), (u'oauth_signature_method', u'HMAC-SHA1'), (u'oauth_nonce', u'25122590467764310441528876248'), (u'oauth_timestamp', u'1528876248')] (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:135)
2018-06-13 16:50:48.049 JST
Normalized params: oauth_consumer_key=gpQh2S0rWdIdTCHfoaA3q2KYL&oauth_nonce=25122590467764310441528876248&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1528876248&oauth_version=1.0 (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:140)
2018-06-13 16:50:48.049 JST
Normalized URI: https://api.twitter.com/oauth/request_token (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:141)
2018-06-13 16:50:48.049 JST
Signing: signature base string: POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_consumer_key%3DgpQh2S0rWdIdTCHfoaA3q2KYL%26oauth_nonce%3D25122590467764310441528876248%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1528876248%26oauth_version%3D1.0 (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:146)
2018-06-13 16:50:48.049 JST
Signature: auihczIZGViCuENQooh5i5BRIA0= (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:153)
2018-06-13 16:50:48.049 JST
Encoding URI, headers and body to utf-8. (lib.zip/oauthlib/oauth1/rfc5849/__init__.py:321)
2018-06-13 16:50:48.049 JST
Updated url: https://api.twitter.com/oauth/request_token (lib.zip/requests_oauthlib/oauth1_auth.py:92)
2018-06-13 16:50:48.050 JST
Updated headers: {'Content-Length': '0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.19.0', 'Connection': 'keep-alive', 'Authorization': 'OAuth oauth_nonce="25122590467764310441528876248", oauth_timestamp="1528876248", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="gpQh2S0rWdIdTCHfoaA3q2KYL", oauth_signature="auihczIZGViCuENQooh5i5BRIA0%3D"'} (lib.zip/requests_oauthlib/oauth1_auth.py:93)
2018-06-13 16:50:48.050 JST
Updated body: None (lib.zip/requests_oauthlib/oauth1_auth.py:94)
2018-06-13 16:50:48.077 JST
Failed : Only tempfile.TemporaryFile is available for use (/base/data/home/apps/b~ktest321986/20180613t164654.410404564513746141/control/contact.py:68)

我在localhost上尝试,没有问题。当我部署到 GAE 时,问题就来了。如何解决这个问题?谢谢

标签: google-app-engineflasktweepy

解决方案


我只是发现 Tweepy 3.5.0 不适用于 GAE。我使用的是 2.3.0 版本,它可以正常工作。


推荐阅读