【问题标题】:(RuntimeError: Form data has been processed already) What does it mean?(RuntimeError: Form data has been processed already) 什么意思?
【发布时间】:2021-03-28 13:26:42
【问题描述】:

我正在开发一个需要发送文件的不和谐机器人。从以前对我有用的文件发送情况中,我能想到的唯一变化是文件的编码是 ISO-8859-1 而不是 utf-8。我用with open(filepath,'r',encoding='ISO-8859-1') as mp3 制作了TextIO 对象,然后在此之下,我使用了await channel.send(file=discord.File(mp3))(在以后的测试中,即使我将discord.File 调用移到另一行,错误在send 方法中)。发送的代码行出现了一个巨大的错误链,以RuntimeError: Form data has been processed already 结尾。这个错误在我的上下文中意味着什么,我该怎么做才能解决它?提前致谢!

作为参考,这里是完整的异常链:

    await coro(*args, **kwargs)
  File "/Users/nathanwolf/Documents/coding/PycharmProjects/lyrics bot/main.py", line 75, in on_message
    await message.channel.send(file=discord.File(mp3))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/abc.py", line 915, in send
    data = await state.http.send_files(channel.id, files=[file], allowed_mentions=allowed_mentions,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/http.py", line 185, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/client.py", line 492, in _request
    req = self._request_class(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 313, in __init__
    self.update_body_from_data(data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 507, in update_body_from_data
    body = body()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/formdata.py", line 168, in __call__
    return self._gen_form_data()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/aiohttp/formdata.py", line 132, in _gen_form_data
    raise RuntimeError("Form data has been processed already")
RuntimeError: Form data has been processed already```

【问题讨论】:

  • 您使用的是旧版本还是修改版本的 discord.py?因为我找不到有关此的任何信息
  • 这不是一个不和谐的错误,它与它出现的 http 请求过程有关
  • @FlexGames 您的建议部分有效:我更新了 discord.py,现在它不会抛出旧错误,它会抛出无法发送空消息错误。感谢您的帮助,但鉴于我在发送调用中指定了内容参数,以及包含一个文件,为什么会抛出空消息错误?
  • 您可以用新代码编辑您的问题,以便我看到吗?

标签: python python-3.x discord.py aiohttp


【解决方案1】:

我修复了它,但不完全清楚我是如何做到的。更新 discord.py 有效,但是当我尝试将 mp3 文件的编码更改为 utf-8 以便 discord 可以读取它时,错误又回来了。我通过不给discord.File() 方法提供TextIO 对象而是给它文件名来解决它。不知怎么的。

【讨论】:

    猜你喜欢
    • 2023-01-24
    • 2018-09-21
    • 2022-06-25
    • 2019-07-23
    • 2020-03-13
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    相关资源
    最近更新 更多