简体   繁体   English

Python 继承 - 类型错误:__init__() 采用 1 个位置参数,但给出了 4 个

[英]Python Inheritance - TypeError: __init__() takes 1 positional argument but 4 were given

import requests
class Poll(requests.session()):
    def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)

with Poll() as p:
# do stuff

>>TypeError: __init__() takes 1 positional argument but 4 were given

I don't understand why an error is being thrown.我不明白为什么会抛出错误。 Doesn't *args take care of any extra positional arguments? *args 不处理任何额外的位置参数吗?

Found the issue.发现问题。 requests.session is a function that returns an instance of the class requests.Session. requests.session 是一个函数,它返回requests.Session 的一个实例。

Fixed code:固定代码:

import requests
class Poll(requests.Session):
    def __init__(self):
         super().__init__()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium TypeError:__init__() 需要 1 个位置参数,但给出了 2 个 - Python Selenium TypeError: __init__() takes 1 positional argument but 2 were given 类型错误:__init__() 需要 1 个位置参数,但给了 2 个 Python - TypeError: __init__() takes 1 positional argument but 2 were given Python 多个 inheritance,TypeError: __init__() 需要 2 个位置 arguments 但给出了 3 个 - multiple inheritance, TypeError: __init__() takes 2 positional arguments but 3 were given 继承 TypeError: __init__() 接受 1 到 2 个位置参数,但给出了 8 个 - inheritance TypeError: __init__() takes from 1 to 2 positional arguments but 8 were given TypeError:__ init __()采用1个位置参数,但给出了2个 - TypeError: __init__() takes 1 positional argument but 2 were given TypeError:__init __()接受1个位置参数,但给出了4个 - TypeError: __init__() takes 1 positional argument but 4 were given 解决错误类型错误:__init__() 需要 1 个位置参数,但给出了 2 个 - Solving the error TypeError: __init__() takes 1 positional argument but 2 were given Django 错误 TypeError: __init__() 需要 1 个位置参数,但给出了 2 个 - Django error TypeError: __init__() takes 1 positional argument but 2 were given Pytorch:[TypeError: __init__() 接受 1 个位置参数,但给出了 2 个] - Pytorch: [TypeError: __init__() takes 1 positional argument but 2 were given] /liveclass/ __init__() 处的类型错误采用 1 个位置参数,但给出了 2 个 - TypeError at /liveclass/ __init__() takes 1 positional argument but 2 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM