How to pass bearer token in API call using python request module? Below I have tried:
import requests
import json
api_url = " "# url
todo = "" #Data to send
headers = {"Content-Type":"application/json"} # how to pass bearer token
response = requests.post(api_url, data=json.dumps(todo), headers=headers)
print(response.json())
CodePudding user response:
Define token before and change headers to:
headers = {"Content-Type":"application/json", "Authorization": f"Bearer {token}"}
