Home > database >  How get bearer token with requests from python
How get bearer token with requests from python

Time:12-13

I'm trying to replicate a login to a page with python and the requests module but I need a token bearer. This site doesn't require a login password connection but just an event code (wooclap.com) I cannot find when the token is recovered by looking at header and json responses. If you can help me Thanks

CodePudding user response:

To send a GET request with a Bearer Token authorization header using Python, you need to make an HTTP GET request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header

CodePudding user response:

once you put in a event code check the network tab on you're chrome console there should be a request wich returns the token. either in the reponse header or the json,

CodePudding user response:

I'd recommend finding it using DevTools in your browser (F12).

In network you can see the login request mainly under headers and response. I've used this to implemented it below in python for you.

import requests

# Set the URL of the login page
url = "https://app.wooclap.com/api/auth/local/login"

# Set the login credentials
data = {"username": "< !!enter username here!! >", "password": "< !!enter password here!! >"}

# Send the login request and store the response
response = requests.post(url, data=data)

# Get the JSON response body
json_response = response.json()

# Get the AWT token from the JSON response
awt_token = json_response.get("token")

# Set the URL of the resource you want to access
url = "https://app.wooclap.com/public/events"

# Set the authorization header of your request, using the Bearer scheme
headers = {"Authorization": f"Bearer {awt_token}"}

# Send the request and store the response
response = requests.get(url, headers=headers)
print(response.text)
  • Related