First to Baidu Cloud application text recognition API, will give you an API key and a secret key, free, up to 500 times a day request.
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 (' Verification Code identification exception, please contact Administrator ')
Baidu authentication Code Recognition API use