【问题标题】:Unable to Access API无法访问 API
【发布时间】:2021-12-01 11:25:02
【问题描述】:

我无法访问 API。

这就是我正在做的:

import os, re
import requests
import logger
from requests_oauthlib import OAuth1

oauth_consumer_key = "123abc"
oauth_secret = "aaabbbccc"

url = "https://example_testing/v1/<ID_VALUE>/reports?"

oauth = OAuth1(oauth_consumer_key, oauth_secret)

output = requests.get(url,auth=oauth)

我不断收到 500 错误。

我做错了什么?

【问题讨论】:

    标签: python-3.x oauth oauth-1.0a


    【解决方案1】:

    我不知道这一点,但显然我需要为标头和有效负载设置值。这解决了我的问题。

    headers = {"Content-Type": "application/json"}
    
    payload = json.dumps({
         "report_format":"csv",
         <other stuff>
    
    }
    
    output = requests.get(url=url, auth=oauth, headers=headers, data=payload)
    

    问题解决

    【讨论】:

      猜你喜欢
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 2023-03-09
      • 2019-12-12
      • 2014-01-28
      • 2021-05-26
      相关资源
      最近更新 更多