I'm trying to read a twitter stream using Python.
The lines in my file, which seems to be correct, look like:
{"delete":{"status":{"id":471622360253345792,"user_id":2513833684,"id_str":"471622360253345792","user_id_str":"2513833684"}}}
When I read this line into memory using readline and call json.loads() on it, I get the following error:
No JSON object could be decoded
I'm thinking I have to convert the line somehow before calling json.loads() on it?
Some notes:
- If I paste the string from the file into IPython and call json.loads() on it, then everything works fine.
When I print the line in IPython, it adds a strange character at the front and puts spaces between the rest of the characters. The first few characters look like:
�{" d e l e t e " : { " s t a t u s
If I display the string in IPython without calling print, the first few characters are:
\xff\xfe{\x00"\x00d\x00e\x00l\x00e\x00t\x00e\x00"\x00:\x00{\x00"\x00s\x00t\x00a\x00t\x00u\x00s\x00"\x00
I have no idea how to fix this.
Edit: By request, the code that reads the twitter stream is here:
https://github.com/uwescience/datasci_course_materials/blob/master/assignment1/twitterstream.py