用python发布请求,给我一个;无法分析请求正文“;错误?检查JSON?但它是JSON格式的
我收到此消息用python发布请求,给我一个;无法分析请求正文“;错误?检查JSON?但它是JSON格式的,python,json,https,python-requests,http-post,Python,Json,Https,Python Requests,Http Post,我收到此消息{“error”:“无法解析请求正文。请检查JSON格式”} 根据以下要求 import requests import json link = "https://api.3dsintegrator.com/v2/authenticate/browser" data = { "pan":"", "amount":"89.95", "month&qu
{“error”:“无法解析请求正文。请检查JSON格式”}
根据以下要求
import requests
import json
link = "https://api.3dsintegrator.com/v2/authenticate/browser"
data = {
"pan":"",
"amount":"89.95",
"month":"01",
"year":"27",
"shipping": {
"line1":"",
"line2":"",
"postCode":"78541",
"city":"",
"state":"",
"country":""
},
"billing": {"line1":"","line2":"","city":"Edinburg","state":"","country":"840"},
"cardHolderName":"",
"messageCategory":"01",
"browser": {"browserAcceptHeader":"application/json","browserJavaEnabled":"false","browserJavascriptEnabled":"true","browserLanguage":"en-US","browserColorDepth":"24","browserScreenWidth":"3200","browserScreenHeight":"1333","browserTZ":"420","browserUserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:87.0) Gecko/20100101 Firefox/87.0"},
"challengeIndicator":"02",
"challengeWindowSize": "01"
}
headers = {
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/json",
"X-3DS-API-KEY": "",
"X-3DS-SDK-VERSION": "",
"Authorization": "Bearer ",
"Content-Length": "731",
"Origin": "https://winbigbonus.com",
"DNT": "1",
"Connection": "keep-alive",
"Referer": "https://winbigbonus.com/",
"TE": "Trailers",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:87.0) Gecko/20100101 Firefox/87.0"
}
response = requests.post(link, headers=headers, data=data).text
print(response)
出于隐私原因,我删除了大部分值。但是我相信我的数据对象已经是json格式的,所以我不确定为什么它会在主体中导致错误并说它无法解析它?您的数据值看起来像一个字典,而不是json字符串。尝试:
response=requests.post(link,headers=headers,data=json.dumps(data)).text
它说AttributeError:module'json'没有属性'parse'我的错误;应该使用转储。我刚刚回答了一个关于javascript的问题,有时会把这两个问题搞混。所以,可能不是数据对象导致了错误?在文章中,你是不是对你得到的东西做了json.loads(),然后对你输出的东西做了json.dumps()?我也尝试过将json.dumps添加到标题中,我得到了一个属性错误:“str”对象没有属性项我将你的数据包装在{所有与}“””相同的数据,现在按照服务器方法所需的方式进行转换。print(“数据类型”,Type(data))json_str=json。dumps(data)print(“json_str类型”,Type(json_str))json_back=json。load(data)print(“json_back类型”,Type(json_back))json_back[“amount”]->