ValueError: No JSON object could be decoded

10.6k Views Asked by At

I am trying the following sample code from the 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)

I keep getting ValueError: No JSON object could be decoded.

2

There are 2 best solutions below

9
On

Hazarding a guess here:

https://api.betfair.com/betting/json-rpc is returning a 404 when making a straight GET. You can see the result in the browser too. A good API returns the proper error code (401 or 403) if it's a header problem. Are you sure you're calling the correct endpoint?

To troubleshoot, we'll need more info. What's the result of changing your last line to:

print response.text

Looking at your update, you're seeing the same thing as me: The requested resource (/betting/json-rpc) is not available.

Either you're sending the wrong header in your POST or, more likely, calling the wrong url. Doing a little digging, I think the correct one is:

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

0
On

The Betfair github code seems to be more current - I've just tried the Python example code on their account and it worked for me. You'll need to set the the appKey and sessionToken in a similar manner to the answer to your previous, closely related question. I would ignore the out of date example code you originally referenced.