[英]python-twitter stream raises JSONDecodeError
When calling for the next tweet of the stream with next(), the following error occurs.用next()调用stream的下一条推文时,出现如下错误。 When I try calling other functions with the same twitter API object, such as GetFriends(), it works fine.
当我尝试使用相同的 twitter API object 调用其他函数时,例如 GetFriends(),它工作正常。 Any help is much appreciated!
任何帮助深表感谢!
Here is the error:这是错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/twitter/api.py", line 4897, in _ParseAndCheckTwitter
data = json.loads(json_data)
File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
And here is the code:这是代码:
import twitter
class Topic:
def __init__(self, topic):
self.api = self.get_twitter_api()
self.stream = self.api.GetStreamFilter(track=[topic])
self.count_tweets()
def get_twitter_api(self):
with open('/twitter_credentials.json') as f:
return twitter.Api(**eval(f.read()))
def count_tweets(self):
while next(self.stream):
print("tweet")
The oldest trick in the book worked: restarting the PC.书中最古老的技巧奏效了:重启电脑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.