0

I have a server side API with the following URL

https://example.com/abc/JSONInterface.jsp?param1=param1_val&param2=param2_val&param3

If you notice the param3 it has no value nor is it null/None

As per this source such URLs are acceptable.

Is it possible to call such an api with python requests library? https://requests.readthedocs.io/en/latest/user/quickstart/

If not is there another library that can handle this?

amitection
  • 2,696
  • 8
  • 25
  • 46
  • requests accepts a dictionary as a param input - https://requests.readthedocs.io/en/latest/user/quickstart/#passing-parameters-in-urls If I create a param with None value the library skips the param. – amitection Mar 22 '23 at 09:15

1 Answers1

1

You might be able to send a string as the params parameter

data = {'param1': 'param1',
        'param2': 'param2',
        'param3': None}

params = '&'.join([k if v is None else f"{k}={v}" for k, v in data.items()])
response = requests.get('https://example.com/abc/JSONInterface.jsp', params=params)
Guy
  • 46,488
  • 10
  • 44
  • 88