APP_ID = '19699070'
API_KEY = 'L9BNPAgFmP7RRB4D0cFlhGUi'
SECRET_KEY = 'eqE1iCj0kcMk53lpjMv3KbBoItX5MrkG'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
}
session = requests.session()
image_url = "https://so.gushiwen.org/user/collect.aspx"
image_page_text = session.get(image_url).text
tree = etree.HTML(image_page_text)
image_src = 'https://so.gushiwen.org' + tree.xpath('//*[@id="imgCode"]/@src')[0]
page_url = requests.get(image_src).content
with open('./test.jpg','wb')as fp:
fp.write(page_url)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return base64.b64encode(fp.read())
image = get_file_content('test.jpg')
""" 调用通用文字识别, 图片参数为本地图片 """
image_code = client.webImage(image);
print(image_code)
{'log_id': 2726567232459694083, 'error_code': 216201, 'error_msg': 'image format error'}
这是错误 头大 不是百度云问题 我的问题 我看他们说转换为base64 但是还是不行 也不知道是不是我转换的额不对 |