Загрузка видео с помощью Python API дает: AttributeError: 'exceptions.UnicodeDecodeError' объект не имеет атрибута 'text'
Я пытаюсь загрузить файл, используя "эталонную" реализацию внутри API PyVimeo.
У меня есть все разрешения и файл с именем "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
1 ответ
Требуется полный путь, например:
file_name = "C:/Users/hp/Downloads/events/189/event.mp4"