在Python中尝试读取下载的twitter txt文件时,出现"JSONDecodeError:Expecting value:line 1 column 1(char 0)"的错误。

2024-10-03 09:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图读取我用Stream下载并以txt格式保存的Twitter流数据时,出现“jsondecodererror:expectingvalue:line1column1(char0)”错误。在

尝试过对代码进行各种修改,就像在类似的问题中所暗示的那样,但都没有奏效。在

如果我从open中删除(errors='ignore'),就会得到以下错误UnicodeDecodeError

# String of path to file: tweets_data_path
tweets_data_path = 'Tweets.txt'

# Initialize empty list to store tweets: tweets_data
tweets_data = []

# Open connection to file
tweets_file = open(tweets_data_path, "r", errors='ignore') 

# Read in tweets and store in list: tweets_data
for line in tweets_file:
    if line.strip():
        tweets_data.append(json.loads(line))

# Close connection to file
tweets_file.close()

当我在Jupyter笔记本中运行上面一行代码时,我遇到了“jsondecodererror:expectingvalue:line1column1(char0)”错误。在


Tags: topath代码intxtdata错误line