0

I have the following code in shell script that I am trying to convert into Python code using request.post:

ESCAPED_PASSWORD = 'hfsudfgi88
USERID = 1234
AUTHO_HOST = 'blah.refdata.com'
AUTH_URL = "https://${AUTH_HOST}/as/tok.oauth2"


resp=$(curl --silent "${AUTH_URL}" --request POST \
            -H "Host: ${AUTH_HOST}" \
            -H "Content-Type: applion/x-www-f-urled" \
            -d "grant_type=client_credentials&client_id=${USERID}&client_secret=${ESCAPED_PASSWORD}")

When I run the above, I get back a json dictionary (success!).

This is my python code:

res = {
            "grant_type":"client_credentials",
            "client_id": USERID,
            "client_secret":ESCAPED_PASSWORD
        }
# send post request
response = requests.post(AUTH_URL, json=res)`

When I run my Python code however, I get back an error:

socket.gaierror: [Errno -2] Name or service not known
jikf
  • 25
  • 6
  • Why are you posting multiple questions? Instead you could have modified the previous question https://stackoverflow.com/questions/76013296/what-does-the-ampersand-mean-in-shell-script-for-authentication-curl-and-how – Gaurav Pathak Apr 14 '23 at 10:35
  • Sorry, I was told once before not to change existing questions.. – jikf Apr 14 '23 at 10:43
  • I think you need to take a look at https://stackoverflow.com/q/16521486/2805824 – Gaurav Pathak Apr 14 '23 at 10:56

0 Answers0