Skip to content

Conversation

@marcus-laia
Copy link

The SDK breaks when trying to run an API call that returns a string body (in csv format, for example).

This is what happens:
json_body = self.json()

  • it fails to convert the body from string to dict, so it returns the string body itself.

if isinstance(json_body, collections_abc.Mapping) and 'error' in json_body:

  • if fails because it checks if json_body is a dict when looking for a dictionary key in it

elif bool(json_body):

  • it's basically just checking that json_body is not empty (str or dict) or False.

if 'success' in json_body:

  • it doesn't check json_body is a dict
  • whenever json_body is a string the code is looking for a substring instead of a dictionary key

return json_body['success']

  • if the string body contains 'success', it will throw an exception when trying to use a string to index a string
  • I've seen this happening when trying to read ad insights with 'success' in a campaign name

return 'Service Unavailable' not in json_body

  • if the string body doesn't contain 'success' but it contains 'Service Unavailable', for any reason, this would return False even if the API call was successful.

@meta-cla meta-cla bot added the CLA Signed label Nov 6, 2025
@meta-codesync
Copy link

meta-codesync bot commented Nov 6, 2025

@stcheng has imported this pull request. If you are a Meta employee, you can view this in D86377538.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant