我正在尝试按照他们的API 文档使用 Pushbullet 发送文件。这是我的功能:
def push_file(AccessToken, file_name):
f = open(file_name, 'rb')
file_type = mimetypes.guess_type(file_name)[0]
print("Uploading {0}...".format(file_name))
try:
data = {
'file_name': file_name,
'file_type' : file_type
}
resp = requests.post(UPLOAD_REQUEST_URL, data=data, auth=(AccessToken, '')).json()
if resp.get('error') != None:
print("Error: {0}".format(resp.get('error')['message']))
return
file_url = resp.get('file_url')
print(file_url)
resp = requests.post(resp.get('upload_url'), data=resp.get('data'), auth=(AccessToken, ''), files={'file': f})
data = {
'type' : 'file',
'file_name' : file_name,
'file_type' : file_type,
'file_url' : file_url,
'body' : ''
}
resp = requests.post(PUSH_URL, data=data, auth=(AccessToken, '')).json()
except requests.exceptions.ConnectionError:
traceback.print_exc()
f.close()
但我不断得到:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='s3.amazonaws.com', port=443): Max retries exceeded with url: /pushbullet-uploads (Caused by <class 'ConnectionResetError'>: [Errno 104] Connection reset by peer)
如果我使用另一个 AccessToken,我仍然会收到此错误,即使这是我第一次发布到该网址。