0

I am trying to make API requests with proper authorization. I looked at Conversion of curl to python Requests but am having trouble putting the authorization headers.

This is what I have so far:

import base64
import http.client
import requests
import json

headers = {
        "Content-Type": "application/json",
        'Authorization': 'Basic %s' % base64.b64encode(b'username:password').decode('ascii'),
    }
payload = {json.dumps({"one":["two:three:four"]})}
url = 'https://website/v1'


r = requests.post(url, data=payload, headers=headers)

if __name__=='__main__':
    print (r.text)

The only difference between the link provided above and my code is that he has query={"tags":["test1","test2"]} I do not have that at all.

This is the curl I am trying to translate to get what I got above.

curl -X POST -u "username:password" -H "Content-Type:application/json" "https://website.com" -d '{"ids":["something:numberOne:numbertwo"]}'

Any help appreciated.

Singha22
  • 1
  • 2
  • 6

0 Answers0