Typeerror: module takes at most 2 arguments 3 given

Having Typeerror: module takes at most 2 arguments 3 given error when you are in the midst of coding?

Well, this error can be frustrating but this can lead you to fix what is the cause of the problem.

Technically this error implies that you are calling a module that has too many arguments however it only accepts specific arguments particularly two.

So, in this article, we will cover how this error occurs, determine its causes, and importantly, provide solutions to it.

What is Typeerror: module takes at most 2 arguments 3 given?

This error Typeerror: module takes at most 2 arguments 3 given indicates that a module is being called with too many arguments. Wherein a module can only accept two arguments, but it was given three.

Further, this could be due to a mistake in the code, where an extra argument was accidentally passed to the module.

Here is how the error occurs:

import math
result = math.pow(2, 3, 4)
print(result)

In this code, we’re trying to use the pow() function from the math module to raise the number 2 to the power of 3, modulo 4.

However, we’ve accidentally passed three arguments to the pow() function instead of two.

As a result, we get a TypeError because we’ve provided an extra argument which apparently, math.pow() function only takes two arguments (base and exponent).

Here is another example that triggered the Typeerror: module takes at most 2 arguments 3 given

import time
current_time = time.localtime(1624824000, True, "UTC")
print(current_time)

In this code, we’re trying to use the localtime() function from the time module to convert the Unix timestamp 1624824000 to local time.

However, we’ve accidentally passed three arguments to the localtime() function instead of two.

Obviously, we will get TypeError because we’ve provided an extra argument, since the time.localtime() function only takes two arguments (the Unix timestamp and an optional flag).

How to fix Typeerror: module takes at most 2 arguments 3 given

Since we know already how this error occurs, here are some solutions to fix this TypeError: module takes at most 2 arguments 3 given error.

Solution 1: Remove the extra argument

import math
result = math.pow(2, 3)
print(result)

In this solution, we’ve removed the third argument to math.pow(), so we’re only passing in the base and exponent.

The code now correctly raises 2 to the power of 3, and the expected output is 8.0.

Output:

8.0

Solution 2: Use a different function that accepts three arguments

import random
dice_roll = random.randrange(1, 7, 2)
print(dice_roll)

In this solution, we’ve replaced the random.randint() function with the random.randrange() function, which can accept three arguments (start, stop, and step).

Then we are generating a random integer between 1 and 6 with a step of 2 (so the possible outcomes are 1 or 3 or 5).

However, the expected output is a random integer between 1 and 6, but only the values 1, 3, or 5 are possible.

So here is the output:

1

Solution 3: Correctly use the function with three arguments

import time
current_time = time.localtime(1624824000)
print(current_time)

In this solution, we’ve corrected the use of time.localtime() by only passing in the Unix timestamp as the first argument.

And here we are not using the optional flag argument.

The expected output is a time.struct_time object representing the local time corresponding to the Unix timestamp 1624824000.

Output:

time.struct_time(tm_year=2021, tm_mon=6, tm_mday=28, tm_hour=4, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=179, tm_isdst=0)

Common reason why this error occur

Here are some common reasons why you might see the TypeError: module takes at most 2 arguments 3 given error message:

  • Passing too many arguments to a function
  • Using the wrong function
  • Providing incorrect arguments
  • Using a different version of the module
  • Incorrect syntax

Additional Resources

Anyway here are some other fixed typeerror wherein you can consider trying when facing these errors:

Conclusion

To conclude, we knew that Typeerror: module takes at most 2 arguments 3 given is caused by using too many arguments to a function, or using the wrong function and providing incorrect arguments.

To fix this error mainly remove the extra argument or use a different function that accepts three arguments.

That’s all for this article. I hope you have learned and fixed the error you are encountering.

Thank you! 😊

Understanding argument-count TypeErrors

Every function call must match the function’s signature — required positionals, defaults, *args, **kwargs. Missing an argument, adding an extra, or using a wrong keyword all raise TypeError.

Common triggers

  • Missing required positional. compute() when signature is compute(x, y).
  • Method called without self. MyClass.method(arg) when it should be instance.method(arg).
  • Keyword argument that doesn’t exist. Typo: open(filepath, mode="r", encodig="utf-8") — encoding is misspelled.
  • Extra positional. Passing 3 args to a function that accepts 2.
  • Mixing positional and keyword. f(1, x=2) when x is the first parameter (double-assignment error).

Diagnostic pattern

# BAD
def send_email(to, subject, body, cc=None):
    ...

send_email("[email protected]", "hi", body_text="Hello")
# TypeError: send_email() missing 1 required positional argument: 'body'
# (because "hi" bound to subject and body_text is unknown)

# GOOD — align keyword args with actual parameters
send_email("[email protected]", "hi", body="Hello")
# or all keyword
send_email(to="[email protected]", subject="hi", body="Hello")

Best practices

  • Use type hints. IDEs and type-checkers flag argument mismatches before you run.
  • Use keyword-only arguments for optional parameters: def send(*, to, subject, body) forces keyword syntax.
  • Read the docstring. Nested libraries sometimes rename kwargs across versions — check the docs.

Frequently Asked Questions

What is Python TypeError and what causes it?

TypeError is raised when an operation is applied to an object of the wrong type. Common patterns: calling a non-callable object, adding incompatible types (str + int), passing the wrong number of arguments, or accessing attributes on a NoneType. Each TypeError message names the operation and expected vs actual types, the fix is almost always to convert types explicitly (int(), str()) or fix the wrong variable assignment.

How do I quickly debug a Python TypeError?

Three steps: (1) Read the full error message, it names the exact operation and types involved. (2) Print the type of every variable in that line: print(type(var1), type(var2)). (3) Check what the function expected vs what you passed. Most TypeError fixes are 1-line type casts or fixing a variable that became None unexpectedly.

Should I catch TypeError or let it propagate?

For internal code, let TypeError propagate, it’s almost always a real bug (wrong type passed). For boundary code (parsing user input, third-party API responses), catch TypeError + ValueError together: try: parsed = int(value) except (TypeError, ValueError): parsed = 0. Catching internal TypeErrors hides bugs.

How do I prevent TypeError in production?

Three patterns: (1) Use type hints (def add(a: int, b: int) -> int) and check with mypy / pyright in CI. (2) Validate inputs at boundaries (Pydantic for FastAPI, DRF serializers for Django). (3) Default values that match expected types (return 0 not None for numeric functions). Static typing catches 80% of TypeErrors before runtime.

Where can I find more TypeError fixes?

Browse the TypeError reference hub for 220+ specific TypeError fixes. For broader Python debugging, see the Python Tutorial hub. For related error types, see ValueError and AttributeError guides.

Glay Eliver


Programmer & Technical Writer at PIES IT Solution

Glay Eliver is a programmer and writer at PIES IT Solution, author of over 600 tutorials at itsourcecode.com. Specializes in JavaScript tutorials, Microsoft Office how-tos (Excel, Word, PowerPoint), and Python error debugging covering ImportError, TypeError, AttributeError, ModuleNotFoundError, and JavaScript ReferenceError. Authored several of the site’s highest-traffic Excel and MS Office reference articles.

Expertise: JavaScript · MS Excel · MS Word · MS PowerPoint · Python · Python ImportError · Python TypeError · Python AttributeError · ModuleNotFoundError · JavaScript ReferenceError · Pygame
 · View all posts by Glay Eliver →