【发布时间】:2019-12-27 07:31:00
【问题描述】:
这是错误: 在第 7 行和第 9 行;
json.decoder.JSONDecodeError:预期值:第 1 行第 1 列(字符 0)
这是我的代码:
import requests
BASE_URL = 'http://127.0.0.1:8000/'
ENDPOINT = 'api/'
def get_resource(id):
resp = requests.get(f"{BASE_URL}{ENDPOINT}{id}/")
print(resp.status_code)
print(resp.json())
id = input("enter some id:")
get_resource(id)
【问题讨论】:
-
检查
resp的Content-type响应头。应该是application/json。 -
是的,我在回复中提到了内容类型。