0

We have a web service(GET) that takes a complex JSON with lists, How do I set it up so that requests sends the generated data as json and not through query string?

Here's the simplified version of the current code and I keep on getting error 403:

def build_get_request_params(table_name):
    data = {'table_data': table_name}
    return data

def get_table_data_prefixed(table_name):
    built = build_get_request_params(table_name)
    response = requests.get("https://www.endpoint", data=json.dump(built))
    print(response.json())
Carlos Miguel Colanta
  • 2,285
  • 3
  • 23
  • 45
  • 1
    `GET` requests can only send parameters through the query string. – Barmar Feb 01 '18 at 22:28
  • Are you sure the web service wants the parameters in JSON format? If it uses `GET`, it almost certainly wants them in URL-encoded format. – Barmar Feb 01 '18 at 22:30
  • Related: https://stackoverflow.com/questions/978061/http-get-with-request-body – Robᵩ Feb 01 '18 at 22:31

1 Answers1

0

Fixed by adding it as params instead:

def build_get_request_params(table_name):
    data = {'table_name': table_name,
            'prefixed': True
            }
    return data


def get_table_data_prefixed(table_name):
    built = build_get_request_params(table_name)
    response = requests.get("http://www.endpoint.com", params=built)
    print(response.json())
Carlos Miguel Colanta
  • 2,285
  • 3
  • 23
  • 45