Why does python think that the request() function is the get() function?

Question:

My requests library doesn’t have any issues except in this class function I created.

import requests
from requests import request


class Business:
    def __init__(self, url, api_key):
        self.url = url
        self.api_key = api_key

    def send_valid_request(self, category, location):
        headers = {'Authorization': 'Bearer ' + api_key}
        params = {'term': category, 'location': location}
        response = request('GET', url, params, None, headers)
#                     ^^
# the error           ^^

        businesses = response.json()['businesses']
        return businesses

    def see_original_name(self, business_name, category, location):
        businesses = self.send_valid_request(category, location)
        ...


category = input(f'Choose the business category: ')
location = input(f'Choose your business location: ')

url = '...'
api_key = '...'

business = Business(url, api_key)


while True:
    question = input(
       'What do you want to know? (choose: name search(NS)/general search(GS)) ')
    if question == 'NS':
        while True:
            business_name = input('Buisness name: ')
            business.see_original_name(business_name, category, location)
      ... 

Error message:

Traceback (most recent call last):

  File ".../mainapp.py", line ..., in <module>
    business.see_original_name(business_name, category, location)

  File ".../mainapp.py", line 20, in see_original_name
    businesses = self.send_valid_request(category, location)

  File ".../mainapp.py", line 15, in send_valid_request
    response = request('GET', url, params, None, headers)

TypeError: request() takes 2 positional arguments but 5 were given

At first I imported only requests and used the get() function at response. After the error I changed it to request but the error was still here.
I think this has to do something with the get() function for dictionaries since it can only take from 1 to 2 arguments.

Python version: 3.8.10

Requests version : 2.28.1

Asked By: Code7G

||

Answers:

Like the error message says, requests.request only takes two positional arguments. The others need to be passed by name:

response = request('GET', url, params=params, headers=headers)
Answered By: RoadieRich