Hi guys, I am constantly getting this error after i run my query:
Traceback (most recent call last):
File "C:\Users\paulg\Desktop\json\apifetch.py", line 16, in <module>
json_data = requests.get(url).json()
File "C:\Python\lib\site-packages\requests\models.py", line 896, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
My query is as follows. Any help on this would be appreciated.
import urllib.parse
import requests
import json
import time
main_api = 'http://sc-api.com/?api_source=live&system=accounts&action=full_profile&'
format = '&format=json'
with open('allmembers.json') as f:
data = json.load(f)
result = []
for element in data:
target_id = element['Handle']
url = main_api + urllib.parse.urlencode({'target_id': target_id}) + format
json_data = requests.get(url).json()
time.sleep(20)
json_status = json_data['request_stats']['query_status']
handle = json_data['data']['handle']
moniker = json_data['data']['moniker']
citizen_number = json_data['data']['citizen_number']
# -----preview if no need to write to file-----
print('target_id: ' + handle + ',', 'Moniker: ' + moniker + ',', 'Citizen Number: ' + citizen_number)
result.append({'target_id': handle, 'Moniker': moniker, 'Citizen Number': citizen_number})
with open('output2.json', 'w') as f:
json.dump(result, f)