DemistoException: Failed to parse json object from response

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DemistoException: Failed to parse json object from response

L1 Bithead

I'm making a request in an integration to an external API

        return self._http_request(
            'POST','export/download',
            headers={'accept': "application/octet-stream",
                     'content-type': "application/x-www-form-urlencoded"},
            data=payload)

and I get back a data stream - it's looks like it should be a JSON array, but is actually not, it's simply a long list of separate JSON objects, e.g.

{"id":1}
{"id":2}
{"id":3}

so I get the error

   File "<string>", line 66, in export_download
   File "<string>", line 9423, in _http_request
   File "<string>", line 9527, in _handle_success
   File "<string>", line 9545, in cast_response
 DemistoException: Failed to parse json object from response: b'{"id":"aaaaa","bd.hostname":"host1.bla"}\n{"id":"bbbbb","bd.hostname":"host2.bla"}\n

and so on...

How do I stop Demisto thinking this is a JSON object. - Line 66 is the one shown

1 accepted solution

Accepted Solutions

L1 Bithead

After much digging, I found you need to set resp_type on the request - not sure why there is no simple documentation on the class, but just needed to add the following to the request

 

resp_type='text'

Had to eventually find the option here

https://raw.githubusercontent.com/demisto/content/master/Packs/Base/Scripts/CommonServerPython/Commo...

 

View solution in original post

1 REPLY 1

L1 Bithead

After much digging, I found you need to set resp_type on the request - not sure why there is no simple documentation on the class, but just needed to add the following to the request

 

resp_type='text'

Had to eventually find the option here

https://raw.githubusercontent.com/demisto/content/master/Packs/Base/Scripts/CommonServerPython/Commo...

 

  • 1 accepted solution
  • 1241 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!