【发布时间】:2019-05-02 12:45:21
【问题描述】:
查看this guide 我正在尝试通过 python 请求从我的 ftpbrick 下载文件。
我设法通过以下命令使用 bash 来做到这一点:
curl https://MY_SUB_DOMAIN.brickftp.com/api/rest/v1/files/MY_FILE_NAME -u MY_API_KEY:x -H 'Accept: application/json'
它会返回一个带有 uri 以供下载的响应。现在我想从 python 做同样的事情。我尝试自己转换,甚至使用this online tool 进行验证。这是我得到的:
In [1]: import requests
In [2]: requests.post('https://MY_SUB_DOMAIN.brickftp.com/api/rest/v1/files/MY_FILE_NAME', headers={'Accept': 'application/json'}, auth=(MY_API_KEY, 'x'))
但这最终导致(在错字修复之后):
Out[7]: <Response [400]>
我做错了什么?
我知道brickfpt for python 3.6。但是,我仍然必须支持 Py2.7
【问题讨论】:
-
首先尝试
headers={'Accept': 'application/json'}(在Accept之后没有:) -
requests.post('https://MY_SUB_DOMAIN.brickftp.com/api/rest/v1/files/MY_FILE_NAME', headers={'Accept': 'application/json'}, auth=(MY_API_KEY, 'x'))? -
@sneep。修复它并得到响应 400
标签: python python-2.7 curl python-requests