请写一段获取token的代码
时间: 2024-06-10 20:06:55 浏览: 122
py代码-获取token,sign
以下是使用Python语言获取token的示例代码:
```
import requests
url = 'https://your_token_api.com'
headers = {'Content-Type': 'application/json'}
payload = {
"username": "your_username",
"password": "your_password"
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
token = response.json()['access_token']
print("Token obtained successfully: ", token)
else:
print("Failed to obtain token")
```
请将 `your_token_api.com` 替换为实际的 API 地址,并填写正确的用户名和密码。如果一切顺利,上述代码将打印出获得的token。
阅读全文