使用此代码,我收到标题中的错误(请参阅下面的完整追溯)。我正在使用站点 API 进行身份验证,然后尝试发布一个 JSON 对象来创建活动,但我无法弄清楚我做错了什么。我是初学者,因此也欢迎您对我的代码提出批评。这是我第一次处理 APIimport requestsimport jsonclient_key = r'xxxxxxxxxxxxx'client_secret = r'yyyyyyyyy'#Password authenticationauthRequest = requests.post("https://backstage.site.com/backstage/oauth/token?client_id="+ client_key +"&client_secret="+ client_secret)data = { "name": "Demo Campaign", "branding_text": "Pizza", "cpc": 0.25, "spending_limit": 1000, "spending_limit_model": "MONTHLY"}token = 'Bearer ' + authRequest.json()['access_token']print(token)url = "https://backstage.site.com/backstage/api/1.0/xxxxx/campaigns/"headers = { 'authorization': 'Bearer ' + token, }resp = requests.post(url=url, data=json.dumps(data), headers={'Content-Type': 'application/json;charset=utf-8','Authorization':"'" + token + "'"})print(resp.json())
添加回答
举报
0/150
提交
取消