0

私は基本的なアプリケーションを持っています。Twitter API 1.1 と Python を使用しています。ローカルで実行している間はエラーは発生しませんが、展開後に DeadlineExceededError エラーが発生しました。ログmsjは次のとおりです。

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~tweetllrio/1.370638782538988919/main.py", line 52, in post
    ''+username+'&max_id='+str(max_id)+'&count=200')
  File "libs/oauth2/__init__.py", line 676, in request
    uri = req.to_url()
  File "libs/oauth2/__init__.py", line 421, in to_url
    query = parse_qs(query)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urlparse.py", line 382, in parse_qs
    for name, value in parse_qsl(qs, keep_blank_values, strict_parsing):
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urlparse.py", line 423, in parse_qsl
    name = unquote(nv[0].replace('+', ' '))
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urlparse.py", line 337, in unquote
    if _is_unicode(s):
DeadlineExceededError

これはmain.pyです

class Search(webapp2.RequestHandler):

    def post(self):
        username = self.request.get("contenta")
        word = self.request.get("contentc")
        header, response = client.request(
            'https://api.twitter.com/1.1/statuses/user_timeline'
            '.json?include_entities=true&screen_name='+username+'&count=1')
        name = json.loads(response)[0]["user"]["name"]
        image = json.loads(response)[0]["user"]["profile_image_url"]
        max_id = json.loads(response)[0]["id"]
        count = 0
        tweets = []
        while count < 18:
            header, response = client.request(
                'https://api.twitter.com/1.1/statuses/user_timeline'
                '.json?include_entities=true&include_rts=false&screen_name='
                ''+username+'&max_id='+str(max_id)+'&count=200')
            for index in range(len(json.loads(response))-1):
                if word in json.loads(response)[index]["text"]:
                    tweets.append(json.loads(response)[index]["text"])
            max_id = json.loads(response)[len(json.loads(response))-1]["id"]
            count += 1

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render(
            {"data": tweets[::-1], "name": name, "image": image, "da":len(tweets)})
        )
class MainPage(webapp2.RequestHandler):

    def get(self):

        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.response.write(template.render({}))

application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/search', Search),
    ('/add', AddUSer),
], debug=True)

助けてくれますか?コードを見たい場合は、教えてください。

4

2 に答える 2

1

Wooble のコメントで述べたように、このスタック オーバーフローの質問には、表示されるDeadlineExceededErrorに対する可能な回答が含まれています。

ただし、問題の解決に役立つように、答えを説明しようとします。

通常の Python ライブラリurlliburllib2httplibを使用して、App Engine でインターネット リソースをフェッチします。ただし、Google App Engine では、これらのライブラリは Google URL Fetch サービスを使用してインターネット リソースをフェッチします。これは、(アプリケーションを実際にホストしているサーバー以外の) 他のサーバーのセットがデータをフェッチすることを意味します。

URL Fetch サービスを使用して App Engine でリソースをフェッチするときに、要求が規定の期限 (アプリケーション指定またはデフォルトの60 秒) 内に完了しない場合、DeadlineExceededException がスローされます。

DeadlineExceededErrorの処理から引用するには

URLFetch を使用して外部 URL にリクエストを行うと、対象の Web サイトにパフォーマンスの問題があるか、通常は応答に 60 秒以上かかる場合、DeadlineExceededErrors が発生する可能性があります。これらの場合、ログに記録された DeadlineExceededErrors のスタック トレースには、URLFetch ライブラリへの呼び出しが含まれている必要があります。

Twitter API リクエストが規定の期限内に完了していない可能性があります。次のいずれかを試してください。

  1. Twitter リソースを非同期的に取得します。
  2. 60 秒を超える明示的な期限 (120 秒など) を指定し、リクエストが正常に完了するかどうかを確認します。このアプローチは、アプリケーションが実行されるシナリオに完全に依存しており、試行錯誤の手法に基づいているため、お勧めしません。
于 2013-10-02T18:58:53.523 に答える