Twint: Unable to save User object returned from Followers method into a json file

Created on 15 Apr 2020  路  6Comments  路  Source: twintproject/twint

l='some_user'
c = twint.Config()
c.Store_object = True
c.User_full = True
c.Username = l

twint.run.Followers(c)
foll = twint.output.users_list

with open(os.path.join(l+'.json'), 'w') as F:
F.write(json.dumps(foll))

I am unable to save this as JSON. It is giving error as "TypeError: Object of type user is not JSON serializable".

question

All 6 comments

twint.output.users_list is a list, so you should iterate over it with a for loop

twint.output.users_list is a list, so you should iterate over it with a for loop

On printing the elements of that list, I am getting "" as output. I need the exact values that get printed on screen when we call the function.

FYI, this is because user.py doesn't have a __repr__ method.

@Sakshimakkar here are the attributes https://github.com/twintproject/twint/wiki/User-attributes#attributes

You call attributes with the dot notation

@Sakshimakkar here are the attributes https://github.com/twintproject/twint/wiki/User-attributes#attributes

You call attributes with the dot notation

That Worked. Thank You :)

Calling values with dot notation is a miserable way to do this. I find it hard to believe there is not a more efficient way!

Was this page helpful?
0 / 5 - 0 ratings