twitter-python-ads-sdk icon indicating copy to clipboard operation
twitter-python-ads-sdk copied to clipboard

AttributeError: 'str' object has no attribute 'get' when HTTP 5xx

Open Patataman opened this issue 4 months ago • 0 comments

When the server responses with a 520 and 524 (afaik, maybe with other 5xx errors also happens)

https://github.com/xdevplatform/twitter-python-ads-sdk/blob/a3dd5819341e77aa469d0b4b3399f0bcd028c80c/twitter_ads/error.py#L13-L16

These lines return the error from the title because response.body is not a dictionary. A possible solution would be

if response.body and 'errors' in response.body:
    if type(response.body) is dict:
        self._details = kwargs.get('details', response.body.get('errors'))
    else:
        self._details = kwargs.get('details', [response.body])
else:
    self._details = None

But I don't know if response.body contains something useful to return as "details". As it is a server side error, I have no way to reproduce it

Patataman avatar Sep 26 '25 09:09 Patataman