gpt4 book ai didi

python - 错误: json.解码器.JSONDecodeError:期望值:第1行第1列(字符0)

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:48 26 4
gpt4 key购买 nike

我想通过 API 从这个 url https://api.hooktheory.com/v1/users/auth 获取一些数据

我可以用 key 输入它,但是一旦我想请求一些数据,它就无法工作,因为出现以下错误。

我已经通过 https://bootstrap.pypa.io/get-pip.py 下载了 pip和导入的请求,我也通过 conda install pip 进行了尝试。什么也解决不了,问题仍然出现。我已经在这里搜索了一些解决方案,但是它。不是重复的。仅供引用:我在 Mac OS X 上使用 Visual Studio 工作。

import requests
import time

login = {"Accept": "application/json",
"Content-Type": "application/json",
"username":"huks",
"password": "XXXX"}


url = "https://api.hooktheory.com/v1/users/auth"
r = requests.post(url, data=login)
print(r.json())

time.sleep(5)

activkey = 'XXXX'
header = {"Authorization": "Bearer " + activkey}

r = requests.get(url+'trends/songs', headers=header)
r.json()

r = requests.get(url+'trends/nodes?cp=4', headers=header)
r.json()

这是回溯+错误消息:

File "/Users/marius/Desktop/INNOLAB/tempCodeRunnerFile.py", line 20, in <module>
r.json()
File "/Users/marius/anaconda3/lib/python3.7/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/Users/marius/anaconda3/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Users/marius/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/marius/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

最佳答案

import requests
import time

login = {"Accept": "application/json",
"Content-Type": "application/json",
"username":"huks",
"password": "XXXX"}


url = "https://api.hooktheory.com/v1/users/auth"
r = requests.post(url, data=login)
print(r.json())

time.sleep(5)

activkey = 'XXXX'
header = {"Authorization": "Bearer " + activkey}

r = requests.get(url+'/trends/songs', headers=header)
r.json()

r = requests.get(url+'/trends/nodes?cp=4', headers=header)
print(r.text) #this will print what is the response you got!
if r.status_code == 200:
print(r.json()) #this will work only if response is JSON

希望评论有意义!

关于python - 错误: json.解码器.JSONDecodeError:期望值:第1行第1列(字符0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57704303/

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