python-twitter 流引发 JSONDecodeError
python-twitter stream raises JSONDecodeError
使用next()调用流的下一条推文时,出现如下错误。当我尝试使用相同的 twitter API 对象调用其他函数时,例如 GetFriends(),它工作正常。非常感谢任何帮助!
这里是错误:
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)
这是代码:
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")
书中最古老的技巧奏效了:重启电脑。
使用next()调用流的下一条推文时,出现如下错误。当我尝试使用相同的 twitter API 对象调用其他函数时,例如 GetFriends(),它工作正常。非常感谢任何帮助!
这里是错误:
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)
这是代码:
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")
书中最古老的技巧奏效了:重启电脑。