Skip to content
Advertisement

KeyError when there exists a key

Using Tweepy, I was trying to live stream the Tweets and save it into database sqlite but as soon as I load the JSON file and store into database the error keeps on occurring saying KeyError : created_at but there already exists a key created_at. I tried with others too, but still the error persists.

Here is my code:

JavaScript

error

JavaScript

Advertisement

Answer

on_data receives all data from the stream, including message types that aren’t Tweet payloads.

The KeyError is almost certainly occurring when one of those other message types is received.

You should check for the existence of an attribute specific to Tweets before using it as a Tweet or consider using on_status instead.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement