0

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.