我是Tweepy(v3.7.0)的新手,我正尝试向某些关注者发送直接消息。但是,JSONDecodeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\font_manager.py in <module>
1355 try:
-> 1356 fontManager = json_load(_fmcache)
1357 if (not hasattr(fontManager, '_version') or
~\Anaconda3\lib\site-packages\matplotlib\font_manager.py in json_load(filename)
891 with open(filename, 'r') as fh:
--> 892 return json.load(fh, object_hook=_json_decode)
893
~\Anaconda3\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
295 parse_float=parse_float, parse_int=parse_int,
--> 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
297
~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
360 kw['parse_constant'] = parse_constant
--> 361 return cls(**kw).decode(s)
~\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
~\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
352 try:
--> 353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
JSONDecodeError: Expecting ':' delimiter: line 4366 column 13 (char 110387)
During handling of the above exception, another exception occurred:
TimeoutError Traceback (most recent call last)
<ipython-input-6-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
30 from cycler import cycler
31 import matplotlib
---> 32 import matplotlib.colorbar
33 import matplotlib.image
34 from matplotlib import rcsetup, style
~\Anaconda3\lib\site-packages\matplotlib\colorbar.py in <module>
30 import matplotlib.collections as collections
31 import matplotlib.colors as colors
---> 32 import matplotlib.contour as contour
33 import matplotlib.cm as cm
34 import matplotlib.gridspec as gridspec
~\Anaconda3\lib\site-packages\matplotlib\contour.py in <module>
16 import matplotlib.colors as mcolors
17 import matplotlib.collections as mcoll
---> 18 import matplotlib.font_manager as font_manager
19 import matplotlib.text as text
20 import matplotlib.cbook as cbook
~\Anaconda3\lib\site-packages\matplotlib\font_manager.py in <module>
1364 raise
1365 except Exception:
-> 1366 _rebuild()
1367 else:
1368 _rebuild()
~\Anaconda3\lib\site-packages\matplotlib\font_manager.py in _rebuild()
1348
1349 if _fmcache:
-> 1350 with cbook._lock_path(_fmcache):
1351 json_dump(fontManager, _fmcache)
1352 _log.debug("generated new fontManager")
~\Anaconda3\lib\contextlib.py in __enter__(self)
110 del self.args, self.kwds, self.func
111 try:
--> 112 return next(self.gen)
113 except StopIteration:
114 raise RuntimeError("generator didn't yield") from None
~\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in _lock_path(path)
1855 This maybe due to another process holding this lock file. If you are sure no
1856 other Matplotlib process is running, remove this file and try again.""".format(
-> 1857 lock_path))
1858 try:
1859 yield
TimeoutError: Lock error: Matplotlib failed to acquire the following lock file:
C:\Users\matij\.matplotlib\fontlist-v300.json.matplotlib-lock
This maybe due to another process holding this lock file. If you are sure no
函数似乎不起作用。我发现了一些旧线程,其中提到过时不推荐使用Twitter的旧直接消息端点,这导致了问题。关于我如何能够通过新端点向我的关注者发送直接消息的任何建议?最新版本的Tweepy是否可以解决此问题?
我尝试了以下代码:
send_direct_message(user_id/screen_name,text)
检索关注者列表:
api.send_direct_message(follower.screen_name,"Hi @"+follower.screen_name)
错误消息:
for follower in limit_handled(tweepy.Cursor(api.followers).items()):
答案 0 :(得分:0)
您必须更改一些官方的tweepy api代码。
第一个更改将是api.py
中的this提交,第二个更改将是binder.py
中的this
之后,您可以在代码中执行以下方法,然后使用此新方法发送消息。
event = {
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": '434259741'
},
"message_data": {
"text": 'This is a new test'
}
}
}
}
api.send_direct_message_new(event)
如果您想进一步了解此问题,here是讨论此问题的链接。