1、 Click on technical documentation
2、 Copy code to pycharm obtain access_token
# encoding:utf-8
import requests
# client_id Obtained for the official website AK, client_secret Obtained for the official website SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【 Obtained from the official website AK】&client_secret=【 Obtained from the official website SK】'
response = requests.get(host)
if response:
print(response.json())
3、
4、 Encapsulate this function into a function
# obtain access_token function
def get_access_token(client_id="3bbdU8i9o7bMg4Wg0KSbNamr", client_secret="GvesuaedzQucRZdvgf9FikS57yc00xMd"):
# client_id Obtained for the official website AK, client_secret Obtained for the official website SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=3bbdU8i9o7bMg4Wg0KSbNamr&client_secret=GvesuaedzQucRZdvgf9FikS57yc00xMd'
print(host)
response = requests.get(host)
if response:
print(response.json(), type(response.json()))
# Access the token password given by the server
print(response.json()["access_token"])
if __name__ == "__main__":
get_access_token()
Python Data analysis learning
Its in the computer python2.7、