Extra data : error while analysing tweets in json format

问题内容:

#!/usr/bin/env python
import tweepy
import json
from tweepy import Stream
from tweepy import OAuthHandler

access_token = ''
access_token_secret = '' 
consumer_key = ''
consumer_secret = ''


 class StdOutListener(tweepy.StreamListener):

    def on_data(self, data):

        # Parsing 
        decoded = json.loads(data)
        #open a file to store the status objects
        file = open('stream.json', 'w')  
        #write json to file
        json.dump(decoded,file,sort_keys = True,indent = 4)
        #show progress
        print ("Writing tweets to file,CTRL+C to terminate the program")
        return True

    def on_error(self, status):
        print (status)

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
twitterStream = Stream(auth, StdOutListener())
twitterStream.filter(track=["xx"])

Above code was written to collect twitter data in the form of json.

And used a python script for sentiment analysis through this post: http://www.alex-hanna.com/tworkshops/lesson-6-basic-sentiment-analysis/

Not sure why I am getting the extra data error.
I am using python 2.6 and cloudera

Error:

Expecting property name: line 1 column 1 (char 1) Extra data: line 1 column 14 - line 1 column 21 (char 14 - 21) Extra data: line 1 column 13 - line 1 column 20 (char 13 - 20) Extra data: line 1 column 12 - line 1 column 47 (char 12 - 47) Extra data: line 1 column 10 - line 1 column 13 (char 10 - 13)

Extra data: line 1 column 10 - line 1 column 15 (char 10 - 15) Extra data: line 1 column 9 - line 1 column 14 (char 9 - 14) Extra data: line 1 column 6 - line 1 column 9 (char 6 - 9) Expecting property name: line 1 column 1 (char 1) Extra data: line 1 column 13 - line 1 column 50 (char 13 - 50) Extra data: line 1 column 14 - line 1 column 70 (char 14 - 70) Extra data: line 1 column 9 - line 1 column 12 (char 9 - 12) Extra data: line 1 column 2 - line 1 column 3 (char 2 - 3) 

Traceback (most recent call last): File "sentimentMapper.py", line 81, in <module> main() File "sentimentMapper.py", line 35, in main if 'text' in data: TypeError: argument of type 'int' is not iterable

Note: Refer to link above for sentimentMapper.py

问题评论:

    
If your data is “too big” then reduce it until you have the minimal needed data reproducing the error. And please post the full error message and the traceback.
    
Owing to the policy of twitter , iam not posting the datset here.
– Amruthapv
51 mins ago
    
You’ll still want to check the formatting of the error messages. Copy/pasting the error message and then selecting it and pressing ctrl-K tends to produce good formatting on Stack Overflow.
    
“Expecting property name: line 1 column 1 (char 1)” sounds like what you are receiving isn’t JSON at all. Can you print out the first few characters of the problematic data for debugging?

原文地址:

https://stackoverflow.com/questions/47754949/extra-data-error-while-analysing-tweets-in-json-format

添加评论

友情链接:蝴蝶教程