【问题标题】:python-twitter stream raises JSONDecodeErrorpython-twitter 流引发 JSONDecodeError
【发布时间】:2020-04-30 15:17:44
【问题描述】:

使用 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")

【问题讨论】:

    标签: python python-twitter


    【解决方案1】:

    书中最古老的技巧奏效了:重启电脑。

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2019-08-06
      • 2017-05-11
      • 2023-02-04
      • 2021-09-13
      • 1970-01-01
      • 2019-05-06
      • 2021-03-31
      • 2021-12-09
      相关资源
      最近更新 更多