TypeError:禁止从 URL 继承类
Posted
技术标签:
【中文标题】TypeError:禁止从 URL 继承类【英文标题】:TypeError: Inheritance a class from URL is forbidden 【发布时间】:2018-10-14 08:46:00 【问题描述】:我在尝试运行我为 Discord 制作的机器人时遇到了这个错误。这发生在下载一些模块后。有没有办法解决这个问题?
Traceback (most recent call last):
File "C:\Users\Jeriel\Desktop\JerryBot\run.py", line 1, in <module>
import discord
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\discord\__
init__.py", line 20, in <module>
from .client import Client, AppInfo
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\discord\cl
ient.py", line 30, in <module>
from .guild import Guild
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\discord\gu
ild.py", line 39, in <module>
from .channel import *
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\discord\ch
annel.py", line 31, in <module>
from .webhook import Webhook
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\discord\we
bhook.py", line 27, in <module>
import aiohttp
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\__
init__.py", line 6, in <module>
from .client import * # noqa
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\cl
ient.py", line 15, in <module>
from . import connector as connector_mod
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\co
nnector.py", line 17, in <module>
from .client_proto import ResponseHandler
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\cl
ient_proto.py", line 6, in <module>
from .http import HttpResponseParser, StreamWriter
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\ht
tp.py", line 8, in <module>
from .http_parser import (HttpParser, HttpRequestParser, HttpResponseParser,
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\ht
tp_parser.py", line 15, in <module>
from .http_writer import HttpVersion, HttpVersion10
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\aiohttp\ht
tp_writer.py", line 304, in <module>
class URL(yarl.URL):
File "C:\Users\Jeriel\AppData\Roaming\Python\Python36\site-packages\yarl\__ini
t__.py", line 230, in __init_subclass__
"is forbidden".format(cls))
TypeError: Inheritance a class <class 'aiohttp.http_writer.URL'> from URL is for
bidden
【问题讨论】:
看起来您可能正在运行旧版本的aiohttp
。尝试运行pip install --upgrade aiohttp
【参考方案1】:
Discord.py rewrite 分支最近在 requirements.txt 和 aiohttp 支持方面存在一些问题。需要手动安装低版本的 yarl 来支持 discord.py 所需的 aiohttp 库。
您需要运行以下命令:
pip install "yarl<1.2"
更新
新版本的 discord.py rewrite 修复了这个问题,您不再需要按照上述解决方案进行操作。正确的做法是从 GitHub 重新下载 discord.py rewrite 并升级包。
【讨论】:
【参考方案2】:我遇到了同样的问题,但为了设置 self-bot,只需将其粘贴到 requirments.txt 中:
yarl<1.2
【讨论】:
【参考方案3】:此答案适用于 aiohttp。如果有人使用 aiohttp 2.2.5 解决了这个问题,可以使用 yarl 的 0.13.0 版本来解决。举个例子:
pip install yarl==0.13.0
【讨论】:
以上是关于TypeError:禁止从 URL 继承类的主要内容,如果未能解决你的问题,请参考以下文章
unittest 模拟和多重继承:TypeError:元类冲突
TypeError: super(type, obj): obj 必须是类型的实例或子类型,仅当我的元类被导入时
fs.FileRead -> TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串、缓冲区或 URL 类型之一。接收类型未定义