gpt4 book ai didi

python - Flask API 错误 JSONDecodeError ("Expecting value", s, err.value) None json.decoder.JSONDecodeError : Expecting value: line 1 column 1 (char 0)

转载 作者:行者123 更新时间:2023-12-05 07:07:18 25 4
gpt4 key购买 nike

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

JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) error

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>

关于python - Flask API 错误 JSONDecodeError ("Expecting value", s, err.value) None json.decoder.JSONDecodeError : Expecting value: line 1 column 1 (char 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62207739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com