将多张卡片发布到附加视频的时间线时,截止日期已超过截止日期

时间:2013-07-25 10:28:42

标签: python google-app-engine google-mirror-api google-glass

首先,我正在使用python over gae,我正在尝试将带有视频附件的卡片推送给访问我的玻璃器皿的所有用户。 这是代码:

        #posting video
        media_link = util.get_full_url(self, '/static/video/man_on_the_moon.mp4')
        resp = urlfetch.fetch(media_link, deadline=2000)
        media_video = MediaIoBaseUpload(io.BytesIO(resp.content), mimetype='video/vnd.google-glass.stream-url',
                                            resumable=True)

        users = Credentials.all()
        for user in users:
            creds = StorageByKeyName(Credentials, user.key().name(), 'credentials').get()
            mirror_service = util.create_service('mirror', 'v1', creds)
            timeline_item = {'text': 'video mode v3'}
            mirror_service.timeline().insert(body=timeline_item, media_body=media_video).execute()

在我的本地机器上,这段代码完美无缺,但在gae上部署它会产生这样的结果:

: HTTPException: Deadline exceeded while waiting for HTTP response from URL: https://www.googleapis.com/upload/mirror/v1/timeline?uploadType=resumable&alt=json&upload_id=AEnB2UqeMjtTAaB7wWw-8yuVoaBdxaD5-mkFx2TJo7PynEXmVCkPLlDFo0l_1t8du_JetszdgmHXF9d-VuD8N0XmwXQVBMynow

关于如何解决这个问题的任何想法? 据我所知,时间轴()。插入每次为我发布卡的用户上传media_body。这在我看来相当耗费资源。正确?

再次感谢你们

这是完整的堆栈:

    Deadline exceeded while waiting for HTTP response from URL: https://www.googleapis.com/upload/mirror/v1/timeline?uploadType=multipart&alt=json
Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~watchup-stage/1.369179617747477845/main_handler.py", line 340, in post
    mirror_service.timeline().insert(body=timeline_item, media_body=media_video).execute()
  File "lib/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "lib/apiclient/http.py", line 676, in execute
    body=self.body, headers=self.headers)
  File "lib/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "lib/oauth2client/client.py", line 490, in new_request
    redirections, connection_type)
  File "lib/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "lib/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "lib/httplib2/__init__.py", line 1286, in _conn_request
    response = conn.getresponse()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/httplib.py", line 500, in getresponse
    raise HTTPException(str(e))
HTTPException: Deadline exceeded while waiting for HTTP response from URL: https://www.googleapis.com/upload/mirror/v1/timeline?uploadType=multipart&alt=json

2 个答案:

答案 0 :(得分:4)

我也遇到过这种类型的问题。为了解决这个问题,我不得不增加HTTP请求的超时时间以及移动到队列。

我向Google Mirror API Python示例提交了一个拉取请求,但它被拒绝以保持“简单”。

您可以在https://github.com/JessieAMorris/mirror-quickstart-python/commit/b67c0ecdf83207b0c3b596173c95a53804b23525结帐我的差异。

基本上,概要是:

  1. 将处理移至队列
  2. import urlfetch和httplib2
  3. 增加urlfetch和httplib2的超时时间,如下所示:

    urlfetch.set_default_fetch_deadline(45)
    httplib2.Http(timeout=45) 
    
  4. 随着这些变化的到来,我不再有超时。

答案 1 :(得分:1)

您有60秒的时间在Google App Engine上完成前端请求。然而,在当地,这种限制似乎并不坚持。

长期处理的唯一选择是任务队列(10分钟截止时间)和后端(无限期)。