import requests
import base64
# client_id 为官网获取的AK, client_secret 为官网获取的SK
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=aAzgARQrG8qCjKKuHfyMieIh&client_secret=C63LvFuqMi8GYuIhVGMkiuKdTT3kuQpe'
response = requests.get(host)
if response:
# print(response.json()['access_token'])
token=response.json()['access_token']
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
f = open('das2.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
access_token = token
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
print(response.json()["image"])
with open('das1.jpg','wb') as file:
dmt = response.json()["image"]
dmt_jm = base64.b64decode(dmt)
file.write(dmt_jm)