-3

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)
M Z
  • 4,571
  • 2
  • 13
  • 27
alex
  • 3
  • 4

3 Answers3

0

My personal preference would be:

import requests

URL = 'whatever'

with requests.get(URL) as response:
    response.raise_for_status()
    print(response.json()

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

DarkKnight
  • 19,739
  • 3
  • 6
  • 22
-2

Use builtin json function of the response

Also best practice to check status codes

response = requests.get(url)
if response.status_code == 200:
  data = response.json()
  print(data)
else:
  print("unexpected response")
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
-2

Note this:

data = json.loads(response.text)

Response has a built-in method for this purpose. It's called as the json()

data = resp.Json()

Additionally, I would preface this with a conditional if check:

if resp.Ok:
    ...
else:
    print('NOK!')
    r.raise_for_status()
rv.kvetch
  • 9,940
  • 3
  • 24
  • 53