烧瓶 API 错误 JSONDecodeError( "Expecting value" , s, err.value) None json.decoder.JSONDecodeError: 期望值:



下面是我为post请求执行的代码并收到此错误

JSONDecodeError("Expecting value", s, err.value( from None json.decoder.JSONDecodeError: 期望值:第 1 行第 1 列(char 0( 错误

import requests,json
request_data = {"files": ["\r\tabs\lg\supp\p\tabrvstring\TStringManager.h @ 118",
"\qt\VION\localbase\base\kernel\qobject.cpp @ 1418"]}
response = requests.post('http://autobot/_search/api/v1.0/',
headers = {'Content-Type':'application/json'},data = json.dumps(request_data))
print("Status code: ", response.status_code)
print("Printing Entire Post Request")
print(response.json())

您的链接没有域:http://autobot###/_search/api/v1.0/

如果写入.comresponse.json()引发相同的错误。因为response没有json数据。尝试断点或print(response.text)

要从文本转换为 json,请使用json.loads(response.text)

import requests, json
request_data = {"files": ["\r\tabs\lg\supp\p\tabrvstring\TStringManager.h @ 118",
"\qt\VION\localbase\base\kernel\qobject.cpp @ 1418"]}
url = 'http://autobot.com/_search/api/v1.0/'
headers = {'Content-Type':'application/json'}
data = json.dumps(request_data)
response = requests.post(url, headers = headers, data = data)
print("Status code: ", response.status_code)
print("Printing Entire Post Request")
#print(response.json())
print(response.text)
# Status code:  200
# Printing Entire Post Request
# <html><head><title>autobot.com</title></head><body><h1>autobot.com</h1><p>Coming soon.</p></body></html>