下面是我的代码:
from requests import post
peer2profit = post("https://peer2profit.com/api/getpeers",data={"_token":"mytoken"})
print(peer2profit.json())
下面是我期望的输出:
{
"totalPeer": 10,
"balance": 0.48045,
"peers": [
{
"id": 108270438,
"serial": null,
"online": 1,
"territorial_dispute": "",
"version": "3.4bA",
"platform": "ANDROID",
"ip": "my ip",
"country": "HR",
And much more...
这是我得到的:
Traceback (most recent call last):
File "c:\Users\skepp\Desktop\test.py", line 24, in <module>
peer2profit = post("https://peer2profit.com/api/getpeers",headers={'accept': 'application/json'},data={"_token": "my token"}).json()['peers']
File "C:\Users\skepp\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\skepp\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\skepp\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\skepp\AppData\Local\Programs\Python\Python310\lib\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)
我有这个错误之前,但我不知道如何修复它!
我在2个不同的HTTP请求工具中尝试了这个帖子请求,它成功了!
以下是一些图片:RestManRequestttp
1条答案
按热度按时间yzuktlbb1#
我没有看到您导入JSON并解析它。