CURL Python 遇到 API 时出现问题

CURL Python Issue When Hitting an API

我想访问的 API 让我使用 CURL,这是我不熟悉的东西。我在 windows 使用 pycharm/spyder IDE(我可以同时使用两者)。

我只使用了图书馆请求,所以不确定如何进行。我使用请求尝试了下面的方法但得到了错误:“TypeError:'str' object is not callable。”我在这里研究了答案,但找不到解决方案。

API 文档中的内容:

    $ curl -H "X-ABCD-Key: api_key" \
    https://api.abcd.com/searches.json

我的做法:

    import requests
    url = "https://api.abcd.com/searches.json"
    auth = ("api_key")
    r = requests.get(url, auth=auth)
    print(r.content)

尝试

import requests
headers = {'X-ABCD-Key': 'api_key'}
response = requests.get('https://api.abcd.com/searches.json', headers=headers)