Всем привет!
Помогите, пожалуйста, исправить ошибку.
from pprint import pprint
import requests
class YandexDisk:
def __init__(self, token):
self.token = token
def get_headers(self):
return {
'Content-Type': 'application/json',
'Authorization': 'OAuth {}'.format(self.token)
}
def _get_upload_link(self, disk_file_path): # Запрос ссылки для загрузки
upload_url = 'https://cloud-api.yandex.net/v1/disk/resources/upload'
headers = self.get_headers()
params = {'path': disk_file_path, 'overwrite': 'true'}
response = requests.get(upload_url, headers=headers, params=params)
pprint(response.json())
return response.json()
#
def upload_file_to_disk(self, disk_file_path, filename):
href_json = self._get_upload_link(disk_file_path=disk_file_path).get('href', '')
href = href_json['href']
response = requests.put(href, data=open(filename, 'rb'))
response.raise_for_status()
if response.status_code == 201:
print('Success')
def get_files_list(self):
files_url = 'https://cloud-api.yandex.net/v1/disk/resources/files'
headers = self.get_headers()
response = requests.get(files_url, headers=headers)
return response.json()
if __name__ == '__main__':
TOKEN = ' '
ya = YandexDisk(token=TOKEN)
pprint(ya.get_files_list())
ya.upload_file_to_disk('List/test2.txt', 'test.txt')