MinionAttack
MinionAttack

Reputation: 540

Convert curl command to http request in python

I'm new on REST API's and I'm unable to make run an http request.

If I try the curl command it works by terminal:

curl \
 --request POST \
 --header "X-OpenAM-Username: user" \
 --header "X-OpenAM-Password: password" \
 --header "Content-Type: application/json" \
 --data "{}" \
 http://openam.sp.com:8095/openamSP/json/authenticate

and the result:

{"tokenId":"AQIC5wM2LY4Sfczw67Mo6Mkzq-srfED3YO8GCSe0Be6wtPs.*AAJTSQACMDEAAlNLABM2NzQ5NjQ4Mjc0MDY0MzEwMDEyAAJTMQAA*","successUrl":"/openamSP/console"}

But now, from my web on Django I want to make a request and I'm unable to make it work, the code that I use it's:

import requests
headers = {'X-OpenAM-Username':'user', 'X-OpenAM-Password':'password', 'Content-Type':'application/json'}
data = {}
r = requests.get('http://openam.sp.com:8095/openamSP/json/authenticate', headers=headers, params=data)

and if I check the answer:

u'{"code":405,"reason":"Method Not Allowed","message":"Method Not Allowed"}'

What I'm doing wrong? I can't see where is my mistake.

Thanks and regards.

Upvotes: 0

Views: 4062

Answers (1)

U.Swap
U.Swap

Reputation: 1939

You are doing everything correct, except POST method just do this:

r = requests.post('http://openam.sp.com:8095/openamSP/json/authenticate', headers=headers, params=data)

The method URL receives is POST method not GET.

Upvotes: 3

Related Questions