Reputation: 1226
My requests API call works, as in it returns a 200, but it fails to load the JSON object.
import requests
xvg_wallet = 'http://api.yiimp.eu/api/wallet?address=DLGuHUwkycBFFajtbMJwMqvcgZ6cVDebCY'
w = requests.get(xvg_wallet).json()
print(w)
Traceback (most recent call last):
File "C:\Users\Brett\Downloads\verge.py", line 4, in <module>
w = requests.get(xvg_wallet).json()
File "C:\Users\Brett\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 826, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\Brett\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Users\Brett\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Brett\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
However, the same GET with the Postman application returns nothing but success.
What am I doing wrong with Python?
Upvotes: 2
Views: 2055
Reputation: 4213
You just need to include headers when you request see the code below:
import requests
xvg_wallet = 'http://api.yiimp.eu/api/walletaddress=DLGuHUwkycBFFajtbMJwMqvcgZ6cVDebCY'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
w = requests.get(xvg_wallet, headers=headers).json()
print(w)
Output:
{'balance': 0.0,
'currency': 'XVG',
'paid24h': 65.10781097,
'total': 68.29277167,
'unpaid': 3.1849607,
'unsold': 3.1849607040682}
Upvotes: 3