Tuesday, 12 July 2022

run curl call in python using requests / http.client

I am trying to execute a curl call in python.

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization:xxxx" -d "{
\"ProductNames\": [
\"PReport\"
],
\"SearchType\": \"FullAddress\",
\"FullAddress\": \"123 Main Street, New York, 10001\",
\"ReferenceId\": \"\"
}" "https://api.aws.com:443/api/rep/grep"

I have tried:

 import http.client 
 import urllib.parse 

 addr = '123 Main Street, New York, 10001'
 prod = 'PReport'
 stype = 'FullAddress'
 

 conn = http.client.HTTPSConnection("https://api.aws.com:443/api/rep/grep") 

    headers = { 
        'Accept': "application/json", 
        'Authorization': "xxxx", 
        } 

    address = urllib.parse.quote(addr)

    url = "https://api.aws.com:443/api/rep/grep?ProductName={}&SearchType={}&FullAddress={}".format(prod, stype, address)

    conn.request("GET", url, headers=headers)

    res = conn.getresponse() 

In swagger, I only see: https://api.aws.com:443/api/rep/grep, not the full request url.

How do I neatly make a curl call in python with the info above?



from run curl call in python using requests / http.client

No comments:

Post a Comment