Python – How to solve TypeError get() Exactly 2 arguments (given 3) in a Python request using the get method

How to solve TypeError get() Exactly 2 arguments (given 3) in a Python request using the get method… here is a solution to the problem.

How to solve TypeError get() Exactly 2 arguments (given 3) in a Python request using the get method

I’m getting an error when using the Request object in Python.
Below is my code.

class APIDOC(Document):
    def request_api(self):
        method_type = self.method_type
        api = self.api
        parameters = self.parameters
        session_object = requests.session()
        self.get_login(session_object)
        if method_type == "POST":   
            data = {}
            for param in parameters:
                data[param.key] = param.value
            response = session_object.post(api,data)
            if response.status_code == 200:
                return response.text
            else:
                return "Error while getting response error code:{0}".format(response.status_code)
        elif method_type == "GET":
            data = {}
            for param in parameters:
                data[param.key] = param.value 
            print("____________________________",data)
            response = session_object.get(api,data)
            if response.status_code == 200:
                return response.text
            else:
                return "Error while getting response error code:{0}".format(response.status_code)

After referencing a document about the request in python, I found that below is something for the “GET” method

r = requests.get('http://httpbin.org/get', params=payload)

But I get an error when doing the same

response = session_object.get(api,data)
TypeError: get() takes exactly 2 arguments (3 given)

Solution

To send parameters using GET, you need to specify them via the keyword:

session_object.get(api, params=data)

Related Problems and Solutions