0

Im struggling with this Dokumentation here:

  • Send your credential base64 encoded to the authentication server.
  • Get a response including an UUID for authentication.
  • Use the UUID to authenticate REST requests.

It shows this request as an example:

**Header**

“`json

{

‘Content-Type’: ‘application/x-www-form-urlencoded’,

‘authorization’: ‘Basic <base64 encoded username:password>’

 }

 “`

 **Body**

 “`json

 {

 ‘grant_type’: ‘client_credentials’

 }

 “`

How do I turn with into a requests.post() ?

1 Answer 1

1

you have to build dictionaries and post them with requests :

import requests
import base64
import json

username = "user"
password = "password"
url = 'https://myurl.com'

headers = {}
headers['Content-Type'] = 'application/x-www-form-urlencoded'
headers['authorization'] = 'Basic ' + base64.b64encode(bytes(username + ':' + password, 'utf-8')).decode('utf-8')

body = {}
body['grant_type'] = 'client_credentials'

r = requests.post(url, data=json.dumps(body), headers=json.dumps(headers))
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.