In browser I got this. I’m trying to get json but got error:
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Code:
import requests
url = 'https://api-mainnet.magiceden.io/idxv2/getBidsByMintAddresses?hideExpired=true&mintAddresses=GXXBt4tzJ6aGoNvz87Xzh1PqXwB4qVRdQdHcX65iXtRZ&direction=1&field=2&limit=500&offset=0'
response = requests.get(url)
data = json.loads(response.text)
print(data)
3
Answers
Use builtin json function of the response
Also best practice to check status codes
Note this:
Response has a built-in method for this purpose. It’s called as the
json()
Additionally, I would preface this with a conditional
if
check:My personal preference would be:
raise_for_status() will raise requests.exceptions.HTTPError if the status code indicates some kind of error. Clearly, you might want to wrap that in try/except