Malformed API Response?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 04:55 PM
I'm using Python to query the REST API. Often times it works, but sometimes it returns malformed JSON. Have other people ran into this? Is there a solution?
headers = {
'Authorization': f'Bearer {bearer_token}',
'Content-Type': 'application/json',
}
params = {
'sysparm_limit': increment,
'sysparm_offset': offset,
'sysparm_display_value': 'true',
'sysparm_exclude_reference_link': 'true',
'sysparm_query': f'sys_created_onBETWEENjavascript:gs.dateGenerate("{start_date}","00:00:00")@javascript:gs.dateGenerate("{end_date}","23:59:59")'
}
data_response = requests.get(target_url, headers=headers, params=params)
data = data_response.json().get('result')
.json() in the last line fails when the JSON is malformed. For example:
- The typical response ends in: "category": "Inquiry / Help"}]}'
- The atypical response would end in "category": "Inquiry / Help"}],""}'
Notice the atypical response includes an extra empty element "". I haven't figured out what causes this, or how to handle it. It seems to happen sporadically.
0 REPLIES 0