Mohammed Alkindy
Mohammed Alkindy

Reputation: 7

I am trying to store twitter trends into a text file but getting errors before storing into a .txt file

my_trends = api.GetTrendsWoeid(my_woe_id)
trends = json.loads(my_trends)

but I get error : raise

TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list

. I am using python 3.7. and python-twitter. What I am doing wrong?

Upvotes: 0

Views: 24

Answers (1)

Patrick Artner
Patrick Artner

Reputation: 51683

Debugging such errors is part of the fun - how to do it?

First step: use python to inspect the thing that makes problems:

print(type(my_trends))       # will tell you it is a list
print(*my_trends)            # prints all list elements wich tells you what they are

then look into the API for what you are using: twitter.api.Api.GetTrendsWoeid which would tell you, that:

documentation thats shows the used method returns a list

which fully explains why you get

TypeError: the JSON object must be str, bytes or bytearray, not list.

Upvotes: 0

Related Questions