Tweepy 回溯 - 类型错误:on_connection_error() 缺少 1 个必需的位置参数:'status_code'



我有一个不和谐机器人,当一个特定的twitter帐户创建一条新的Tweet时,它利用Tweepy(4.8)在我的频道中发布。这招以前管用,但最近不行了。有什么想法或帮助吗?这是我的代码:

async def twitter():
await bot.wait_until_ready()
consumer_key = os.getenv('consumer_key')
consumer_secret = os.getenv('consumer_secret')
access_token = os.getenv('access_token')
access_secret = os.getenv('access_secret')
class StreamCollector(tweepy.asynchronous.AsyncStream):
async def on_status(self, data):
tweet = json.dumps(data._json)
tweet = json.loads(tweet)

if tweet['text'][0:4] == '[PC]':
print(tweet)
await channel.send('https://twitter.com/PUBG_Support/status/'+tweet['id_str'])
else:
pass
async def on_connection_error(self, status_code):
if status_code == 420:
#returning False in on_data disconnects the stream
return False
elif status_code == 406:
return False

stream = StreamCollector(
consumer_key, consumer_secret, access_token, access_secret
)
channel = bot.get_channel(#CHANNELCODE) #CRKR general channel
stream.filter(follow=[882248998547070981]) #this is pubg support ID

和完整的错误:

Stream encountered an exception
Traceback (most recent call last):
File "/home/ryandiscordboyzbot/.local/lib/python3.8/site-packages/tweepy/asynchronous/streaming.py", line 109, in _connect
async for line in resp.content:
File "/home/ryandiscordboyzbot/.local/lib/python3.8/site-packages/aiohttp/streams.py", line 39, in __anext__
rv = await self.read_func()
File "/home/ryandiscordboyzbot/.local/lib/python3.8/site-packages/aiohttp/streams.py", line 338, in readline
await self._wait("readline")
File "/home/ryandiscordboyzbot/.local/lib/python3.8/site-packages/aiohttp/streams.py", line 306, in _wait
await waiter
aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ryandiscordboyzbot/.local/lib/python3.8/site-packages/tweepy/asynchronous/streaming.py", line 134, in _connect
await self.on_connection_error()
TypeError: on_connection_error() missing 1 required positional argument: 'status_code'

您使用参数status_code声明函数,但是tweepy不支持该函数的此参数。如果你把这个去掉,它应该可以正常工作。

关于这个函数的文档可以在这里找到:https://docs.tweepy.org/en/stable/asyncstreamingclient.html#tweepy.asynchronous.AsyncStreamingClient.on_connection_error。其中还显示on_connection_error没有参数。

最新更新