close

[Solved] TypeError: module.__init__() takes at most 2 arguments (3 given)

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: module.init() takes at most 2 arguments (3 given) in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: module.init() takes at most 2 arguments (3 given) Error Occurs?

Today I get the following error TypeError: module.init() takes at most 2 arguments (3 given) in python.

How To Solve TypeError: module.init() takes at most 2 arguments (3 given) Error ?

  1. How To Solve TypeError: module.init() takes at most 2 arguments (3 given) Error ?

    To Solve TypeError: module.init() takes at most 2 arguments (3 given) Error Your error is happening because Object is a module, not a class. So your inheritance is screwy.

  2. TypeError: module.init() takes at most 2 arguments (3 given)

    To Solve TypeError: module.init() takes at most 2 arguments (3 given) Error Your error is happening because Object is a module, not a class. So your inheritance is screwy.

Solution 1

Your error is happening because Object is a module, not a class. So your inheritance is screwy.

Change your import statement to:

from Object import ClassName

and your class definition to:

class Visitor(ClassName):

or

change your class definition to:

class Visitor(Object.ClassName):
   etc

Solution 2


In case anyone else is like me and needs a little more help, here’s what was going on in my situation.

  • responses is a module
  • Response is a base class within the responses module
  • GeoJsonResponse is a new class derived from Response

Initial GeoJsonResponse class:

from pyexample.responses import Response

class GeoJsonResponse(Response):

    def __init__(self, geo_json_data):

Looks fine. No problems until you try to debug the thing, which is when you get a bunch of seemingly vague error messages like this:

from pyexample.responses import GeoJsonResponse ..\pyexample\responses\GeoJsonResponse.py:12: in (module) class GeoJsonResponse(Response):

E TypeError: module() takes at most 2 arguments (3 given)

=================================== ERRORS ====================================

___________________ ERROR collecting tests/test_geojson.py ____________________

test_geojson.py:2: in (module) from pyexample.responses import GeoJsonResponse ..\pyexample\responses \GeoJsonResponse.py:12: in (module)

class GeoJsonResponse(Response): E TypeError: module() takes at most 2 arguments (3 given)

ERROR: not found: \PyExample\tests\test_geojson.py::TestGeoJson::test_api_response

C:\Python37\lib\site-packages\aenum__init__.py:163

(no name ‘PyExample\ tests\test_geojson.py::TestGeoJson::test_api_response’ in any of [])

The errors were doing their best to point me in the right direction, and @Mickey Perlstein’s answer was dead on, it just took me a minute to put it all together in my own context:

I was importing the module:

from pyexample.responses import Response

when I should have been importing the class:

from pyexample.responses.Response import Response

Hope this helps someone. (In my defense, it’s still pretty early.)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read