skip to Main Content

I am trying to make a twitter bot that uses requests library to get data from nytimes api.
There is a line in the code

resp = requests.get(API_ENDPOINT, my_params)

Now this works very well when I run it locally. So I uploaded it to pythonanywhere. The moment I tried to run it I got this error:

resp = requests.get(API_ENDPOINT, my_params)
TypeError: get() takes exactly 1 argument (2 given)

What is happening? I have started using requests as well as pythonanywhere recently. So I have literally no idea where to start debugging.

2

Answers


  1. You have different requests versions installed on PythonAnywhere and locally.


    From what I see requests version installed on PythonAnywhere is 2.4.0. At that point, you had to specify params keyword argument explicitly:

    requests.get(url, **kwargs)

    And you have to write:

    resp = requests.get(API_ENDPOINT, params=my_params)
    

    In the most recent version (2.10.0 at the moment), you can have params specified as a positional argument:

    requests.get(url, params=None, **kwargs)

    resp = requests.get(API_ENDPOINT, my_params)
    
    Login or Signup to reply.
  2. You can do it like this:

    API_ENDPOINT = 'http://your_endpoint_url.com'
    
    my_params = {'key1': 'value1', 'key2': 'value2'} 
    
    r = requests.get(API_ENDPOINT, params=my_params) # notice params is named named
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search