Response object is not a dict



My app is approved for the developer access. I am trying out twitter_ads SDK with these simple lines of python code.

# initialize the client
client = Client(

account = client.accounts(id=ACCOUNT_ID)

On this line above, I am getting this exception. How can I find out what went wrong?

Traceback (most recent call last):
File “”, line 15, in
account = client.accounts(id=ACCOUNT_ID)
File “/Library/Python/2.7/site-packages/twitter_ads/”, line 89, in accounts
return Account.load(self, id) if id else Account.all(self)
File “/Library/Python/2.7/site-packages/twitter_ads/”, line 54, in load
return Cursor(klass, request, init_with=[client])
File “/Library/Python/2.7/site-packages/twitter_ads/”, line 29, in init
File “/Library/Python/2.7/site-packages/twitter_ads/”, line 91, in __from_response
File “/Library/Python/2.7/site-packages/twitter_ads/”, line 43, in from_response
value = response.get(name, None)
AttributeError: ‘unicode’ object has no attribute ‘get’

When I print out the response object, which is a string, it becomes just ‘name’.


Have you tried running any of the provided examples that are in the twitter-python-ads-sdk repository? Could you give those a go? Those should all work as expected and you can build your code up from those as a reference.


Thank you for your response Andrs. Yes, this is actually from running the examples and it failed on this line:

I debugged this a little bit and see the data element I got back in response is a dict

But it seems the SDK code expect it to be a list here.

I modified my local to wrap data in a list which helped pass the line above and the example appears fine executing
account = client.accounts(id=ACCOUNT_ID)

However if I want to immediately do

for campaign in account.campaigns():

I got

AttributeError: ‘Cursor’ object has no attribute ‘campaigns’.

the account should be a Account class not Cursor, right?


Thanks for digging into this and being so thorough @AngryNotBird :slightly_smiling:

It sounds like you might’ve stumbled upon a bug - do you mind opening up an issue on our GitHub repo? If you think you’ve addressed it with your changes in please do go ahead and open a pull request - we love community contributions! Have a look at our contributing guidelines so you know what you need to do.

In terms of wanting to do something like for campaign in account.campaigns(), wrapping account.campaigns() around list should do the trick for you (have a look at this quick start example) :slightly_smiling: