ValueError:无法解码任何JSON对象

2024-05-16 11:25:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试betfair api中的以下示例代码:

import requests
import json

url="https://api.betfair.com/betting/json-rpc"
header = { 'X-Application' : appKey,  'X-Authentication' : sessionToken, 'content-type' : 'application/json' }
jsonrpc_req='{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listCompetitions", "params": {"filter":{ "eventTypeIds" : [1]  }}, "id": 1}'
print json.dumps(json.loads(jsonrpc_req), indent=3)
print " "
response = requests.post(url, data=jsonrpc_req, headers=header)
print json.dumps(json.loads(response.text), indent=3)

我总是得到ValueError: No JSON object could be decoded


Tags: importapijsonurl示例responserequestsreq
2条回答

Betfair github代码似乎更为流行——我刚刚在他们的帐户上尝试了Python示例代码,它对我很有用。您需要以与前面的答案类似的方式设置appKey和sessionToken,非常接近related question。我将忽略您最初引用的过时示例代码。

猜猜看:

https://api.betfair.com/betting/json-rpc在进行笔直操作时返回404。你也可以在浏览器中看到结果。如果是头问题,一个好的API会返回正确的错误代码(401或403)。您确定正在调用正确的终结点吗?

要排除故障,我们需要更多信息。将最后一行更改为:

print response.text

看看你的更新,你看到的和我一样:The requested resource (/betting/json-rpc) is not available.

要么在POST中发送了错误的头,要么更可能是调用了错误的url。做一点挖掘,我认为正确的方法是:

https://api.developer.betfair.com/betting/json-rpc

相关问题 更多 >