1

我正在尝试使用 PyVimeo API 中的“参考”实现上传文件。

我拥有所有权限和一个名为“config.json”的文件,其中包含密钥和令牌(此处未显示)。

我在脚本中引用的 mp4 文件实际上存在并且我能够打开它。

但是当我运行脚本时,出现以下错误:

Traceback (most recent call last):
  File "./vimeo_upload2.py", line 25, in <module>
    'description': "This video was uploaded through the Vimeo API's "
  File "/usr/local/lib/python2.7/dist-packages/vimeo/upload.py", line 72, in upload
    return self.__perform_tus_upload(filename, attempt)
  File "/usr/local/lib/python2.7/dist-packages/vimeo/upload.py", line 147, in __perform_tus_upload
    'Unexpected error when uploading through tus.'
  File "/usr/local/lib/python2.7/dist-packages/vimeo/exceptions.py", line 88, in __init__
    super(VideoUploadFailure, self).__init__(response, message)
  File "/usr/local/lib/python2.7/dist-packages/vimeo/exceptions.py", line 27, in __init__
    self.message = self.__get_message(response)
  File "/usr/local/lib/python2.7/dist-packages/vimeo/exceptions.py", line 20, in __get_message
    message = response.text
AttributeError: 'exceptions.UnicodeDecodeError' object has no attribute 'text'

请注意:我拥有上传视频等的所有权限;-)

这是我正在使用的代码:

#!/usr/bin/env python
import json
import os
import vimeo

config_file = os.path.dirname(os.path.realpath(__file__)) + '/config.json'
config = json.load(open(config_file))

if 'client_id' not in config or 'client_secret' not in config:
    raise Exception('We could not locate your client id or client secret ' + 'in `' + config_file + '`. Please create one, and ' + 'reference `config.json.example`.')

# Instantiate the library with your client id, secret and access token
# (pulled from dev site)
client = vimeo.VimeoClient( token=config['access_token'], key=config['client_id'], secret=config['client_secret'])

# Create a variable with a hard coded path to your file system
file_name = "events/189/event.mp4"

print 'Uploading: %s' % file_name

try:
    # Upload the file and include the video title and description.
    uri = client.upload(file_name, data={
                        'name': 'Vimeo API SDK test upload',
                        'description': "This video was uploaded through the Vimeo API's "
                          })

    # Get the metadata response from the upload and log out the Vimeo.com url
    video_data = client.get(uri + '?fields=link').json()
    print '"%s" has been uploaded to %s' % (file_name, video_data['link'])

    # Make an API call to edit the title and description of the video.
    client.patch(uri, data={
                            'name': 'Vimeo API SDK test edit',
                            'description': "This video was edited through the Vimeo API's "
                   })

    print 'The title and description for %s has been edited.' % uri

    # Make an API call to see if the video is finished transcoding.
    video_data = client.get(uri + '?fields=transcode.status').json()
    print 'The transcode status for %s is: %s' % (
                                                uri,
                                        video_data['transcode']['status']
                                            )
except vimeo.exceptions.VideoUploadFailure as e:
    # report it to the user.
    print 'Error uploading %s' % file_name
    print 'Server reported: %s' % e.message
4

1 回答 1

0

它需要这样的完整路径:

file_name = "C:/Users/hp/Downloads/events/189/event.mp4"
于 2021-12-20T13:29:17.933 回答