【问题标题】:api key problem - how to convert curl to python requests for accessing ftpbrickapi关键问题-如何将curl转换为python请求以访问ftpbrick
【发布时间】: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


【解决方案1】:

您的 curl 命令发送一个 GET 请求,而 Python 发送一个 POST。尝试将requests.post(...) 更改为requests.get(...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 2020-05-29
    • 2019-06-28
    • 1970-01-01
    相关资源
    最近更新 更多