如何解决使用 twitter API 的 python 中的 Tweepy/JSONDecodeError 错误
我试图重现这个例子 [https://github.com/bauyrjanj/NLP-TwitterData/blob/master/TwitterData%20-%20Problem%20Statement%20%26%20Data%20Collection.ipynb]使用带有 'tweepy' 的 twitter 数据,一切都会运行,直到这些代码行:
不知道怎么解决,
谢谢:)
tweets_data_path = 'tweets.txt'
tweets_data=[]
tweets_file_1 = open(tweets_data_path,'r')
# Read in tweets and store in list: tweets_data
for line in tweets_file_1:
tweet = json.loads(line)
tweets_data.append(tweet)
# Close connection to file
tweets_file_1.close()
# Print the keys of the first tweet dict
print(tweets_data[0].keys())
JSONDecodeError Traceback (most recent call last)
<ipython-input-50-e43cd5de029e> in <module>
4 # Read in tweets and store in list: tweets_data
5 for line in tweets_file_1:
----> 6 tweet = json.loads(line)
7 tweets_data.append(tweet)
8
/opt/anaconda3/lib/python3.8/json/__init__.py in loads(s,cls,object_hook,parse_float,parse_int,parse_constant,object_pairs_hook,**kw)
355 parse_int is None and parse_float is None and
356 parse_constant is None and object_pairs_hook is None and not kw):
--> 357 return _default_decoder.decode(s)
358 if cls is None:
359 cls = JSONDecoder
/opt/anaconda3/lib/python3.8/json/decoder.py in decode(self,s,_w)
335
336 """
--> 337 obj,end = self.raw_decode(s,idx=_w(s,0).end())
338 end = _w(s,end).end()
339 if end != len(s):
/opt/anaconda3/lib/python3.8/json/decoder.py in raw_decode(self,idx)
353 obj,end = self.scan_once(s,idx)
354 except stopiteration as err:
--> 355 raise JSONDecodeError("Expecting value",err.value) from None
356 return obj,end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。