Home > Net >  how to pass bearer token in python api
how to pass bearer token in python api

Time:01-26

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}"}

  •  Tags:  
  • Related