通过API将视频上传到Vimeo时出现超时错误

时间:2014-05-22 13:15:59

标签: python tornado vimeo-api

我有一个Python脚本,利用最新的Vimeo API(https://developer.vimeo.com/api/)将一些视频上传到我的Vimeo帐户。

这是一个略微简化的形式,脚本基本上是这样的:

from vimeo import VimeoClient
vimeo = VimeoClient('my_token_here')
uid = vimeo.upload('/path/to/file.mov')

file.mov为3MB或更少时,一切正常并且文件已成功上传。但是,对于较大的文件,我会收到超时错误:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 79, in __call__
    return do_upload()
  File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 70, in do_upload
    self.upload_segment(upload_uri, _range, video_data, filetype or 'mp4')
  File "/home/fabio/.virtualenvs/venv/src/vimeo/vimeo/uploads.py", line 135, in upload_segment
    body=data, headers=request_headers)
  File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/httpclient.py", line 85, in fetch
    self._async_client.fetch, request, **kwargs))
  File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/ioloop.py", line 389, in run_sync
    return future_cell[0].result()
  File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/concurrent.py", line 131, in result
    return super(TracebackFuture, self).result(timeout=timeout)
  File "/home/fabio/.virtualenvs/venv/lib/python2.7/site-packages/tornado/concurrent.py", line 65, in result
    raise self._exception
HTTPError: HTTP 599: Timeout

这是我正在使用的vimeo库:https://github.com/vimeo/vimeo.py

我的虚拟环境中的Tornado库已更新为3.2.1版本。

给我的任何提示?

1 个答案:

答案 0 :(得分:0)

Tornado source开始,HTTPClient正在使用的vimeo的默认请求超时为20秒。它看起来像Vimeo library attempts to upload as much of the video as possible,然后查询服务器以查看成功上传了多少。上传视频的时间可能超过20秒,因此超时。我不相信他们会正确处理这个问题,因为你从Tornado收到超时错误,但似乎他们想要支持整个文件不能立即上传。

您可以尝试修改我上面链接的vimeo库代码,以通过将本地副本中的链接行更改为以下内容来实现更长的超时:

    r = HTTPClient().fetch(upload_uri, method="PUT",
                           body=data, headers=request_headers, 
                           request_timeout=9999.0)

如果这不起作用,您可以尝试在github问题跟踪器上提出问题,而实际从事该项目的人可能会对您提供进一步的帮助。