python中处理验证码的方式简单的是可以使用pytesser.image_to_string(image).strip()获取图片中的验证码,
但是在使用时会出现以下错误
Traceback (most recent call last):
File "F:\Autotest_omengadmin\public\common.py", line 150, in getcode
code=pytesser.image_to_string(qq).strip() #使用image_to_string识别验证码
File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 31, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "C:\Python27\lib\site-packages\pytesser\pytesser.py", line 21, in call_tesseract
proc = subprocess.Popen(args)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
File "D:\Ӧԃɭݾ\Pycharm\PyCharm 4.0.5\helpers\pydev\pydev_monkey.py", line 299, in new_CreateProcess
return getattr(_subprocess, original_name)(appName, patch_arg_str_win(commandLine), *args)
WindowsError: [Error 2]
处理方法:在py文件开头加上:
importos
os.chdir('C:\Python27\Lib\site-packages\pytesser')#改变当前工作目录到指定的路径
备注:修改当前工作目录后,需要在回到当前目录,否则通过相对路径获取不到文件(弊端)
http://tieba.baidu.com/p/4139117491
http://www.runoob.com/python/os-chdir.html