Skip to content Skip to sidebar Skip to footer

Twitter Stream Api Gives Jsondecodeerror("expecting Value", S, Err.value) From None

I am using the stream API of Twitter (through tweepy) to collect tweets matching certain criteria, but when I use json.loads() to parse the created jsonl file I get this following

Solution 1:

When writing to file, in the Listener class, you can try:

defon_data(self, data):
    withopen('filename.json', 'a', newline='\n') as f:
        f.write(data)

I also faced this problem on Windows machines. That's because Windows uses CR LF line ending while Linux uses LF.

If you try to read a single tweet, I don't think it would give an error as you can see here:

json.decoder.JSONDecodeError: Expecting value: line 2column1 (char1)  

This is more likely a bug in the json python package rather than the TwitterAPI.

See: The modern way: use newline=''

More on line endings: On Wikipedia, as always.

Solution 2:

Inside the for loop, you can try:

tweet = json.loads(line.decode())

or remove the for loop and try:

tweets = json.load(f)

Solution 3:

I met the same problem just now.

I tried to use the json analyzer to test the json string and found there are some wrong formats.

Such as, False should be "False", None should be "None".

I mean first you should check whether the format of the json string is correct, and one method is to test it on a website that specifically converts json format.

Hope the answer is a little helpful for you.

Post a Comment for "Twitter Stream Api Gives Jsondecodeerror("expecting Value", S, Err.value) From None"