简体   繁体   中英

How get bearer token with requests from python

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

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,

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM