【发布时间】:2016-04-20 12:45:05
【问题描述】:
无法使用 python 程序从 zamzar api 下载转换后的文件,正如 https://developers.zamzar.com/docs 中指定的那样,但因为我正确地使用了代码和 api 密钥。它只显示错误代码:20。在这个错误后面浪费了 4 小时,请有人。
import requests
from requests.auth import HTTPBasicAuth
file_id =291320
local_filename = 'afzal.txt'
api_key = 'my_key_of_zamzar_api'
endpoint = "https://sandbox.zamzar.com/v1/files/{}/content".format(file_id)
response = requests.get(endpoint, stream=True, auth=HTTPBasicAuth(api_key, ''))
try:
with open(local_filename, 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.flush()
print("File downloaded")
except IOError:
print("Error")
这是我用来下载转换文件的代码。
【问题讨论】:
-
请复制完整的输出/回溯。