调用python实现百度图片转换出错,纯小白
一直弹出 No module named 'requests'不知道应该怎么解决
代码都是抄的:'(weeqw
# encoding:utf-8
import requests
import base64
def post_tonke():
url = " https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime"
params = {
'grant_type': 'client_credentials',
'client_id': 'ih***********Gj',
'client_secret': 'hzLxh2*************oyoNe5'
}
response = requests.post(url, params) # 按住ctrl可以进入函数post查看
access_token = eval(response.text)['access_token']# eval()执行里面的表达式
return access_token # 将鉴权之后的值进行返回
'''
人像动漫化
'''
request_url = ' https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime'
with open('D:\桌面.1\作图', '包') as file: # 读取图片
img = base64.b64encode(file.read())# 编码图片
params = {"image": img, # 通过表单提交形式提交access_token
"access_token": post_tonke()}
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
with open('D:\桌面.1', '转换成功1') as file: # 保存图片
animer = response.json()['image']
image = base64.b64decode(animer) # 解码
file.write(image) 应该是没装requests
页:
[1]