zoukankan      html  css  js  c++  java
  • 百度 验证码识别API 使用

    先到百度云申请文字识别API ,会给你一个API KEY和一个SECRET KEY,免费,一天最多500次请求。


    try:
    temp_url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【API KEY】&client_secret=【SECRET KEY】'
    temp_res = requests.post(temp_url)
    temp_token = eval(temp_res.text)['access_token']
    temp_url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=' + temp_token
    temp_headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    temp_file = open('code_xjtu.png', 'rb')
    temp_image = temp_file.read()
    temp_file.close()
    temp_data = {
    'image': base64.b64encode(temp_image)
    }
    temp_data = urllib.parse.urlencode(temp_data)
    temp_res = requests.post(url=temp_url, data=temp_data, headers=temp_headers)
    code = int(eval(temp_res.text)['words_result'][0]['words'])
    except Exception as e:
    print(e)
    print('验证码识别异常,请联系管理员')
  • 相关阅读:
    创建被访问的swf文件
    BFS寻路算法的实现
    Flex里的命名空间,fx、mx、s【转】
    Flex的基础用法【转】
    Pow(x, n)
    Roman to Integer
    Integer to Roman
    Divide Two Integers
    Single Number II
    Single Number I
  • 原文地址:https://www.cnblogs.com/zealousness/p/8953714.html
Copyright © 2011-2022 走看看