国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Python:IOError:imagefileistruncated的解決辦法

2019-11-14 17:16:11
字體:
供稿:網(wǎng)友

代碼如下:

#coding:utf-8from PIL import Imageimport pytesseractdef test():    im = Image.open(r"pic.gif")    vcode = pytesseract.image_to_string(im)    PRint vcode

執(zhí)行以上代碼進(jìn)行簡單驗(yàn)證碼識(shí)別的時(shí)候會(huì)拋出一個(gè)異常:

Traceback (most recent call last):  File "D:/test/vcode.py", line 15, in <module>    main()  File "D:/test/vcode.py", line 9, in main    test()  File "D:/test/test.py", line 8, in test    vcode = pytesseract.image_to_string(im)  File "build/bdist.win32/egg/pytesseract/pytesseract.py", line 143, in image_to_string  File "D:/Program Files (x86)/Python/Python27/lib/site-packages/PIL/Image.py", line 1749, in split    self.load()  File "D:/Program Files (x86)/Python/Python27/lib/site-packages/PIL/ImageFile.py", line 232, in load    "(%d bytes not processed)" % len(b))IOError: image file is truncated (5 bytes not processed)

解決辦法是,再添加如下2句代碼:

from PIL import ImageFileImageFile.LOAD_TRUNCATED_IMAGES = True

最終,完整的代碼如下:

#coding:utf-8from PIL import Imageimport pytesseractfrom PIL import ImageFileImageFile.LOAD_TRUNCATED_IMAGES = Truedef test():    im = Image.open(r"pic.gif")    vcode = pytesseract.image_to_string(im)    print vcode

相關(guān)文章:

關(guān)于利用python進(jìn)行驗(yàn)證碼識(shí)別的一些想法:http://m.survivalescaperooms.com/xiaowuyi/archive/2012/09/10/2675286.html

python利用pytesser模塊實(shí)現(xiàn)圖片文字識(shí)別:http://www.jinglingshu.org/?p=9281

驗(yàn)證碼圖片字符識(shí)別兩種python實(shí)現(xiàn)方法:http://vipscu.blog.163.com/blog/static/18180837220134234528457/

python模擬登陸登陸一:驗(yàn)證碼與cookies的同步處理思路:http://www.dabu.info/python-login-crawler-captcha-cookies.html

原文地址:http://m.survivalescaperooms.com/hongfei/p/4436767.html


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 临湘市| 伊春市| 温宿县| 四川省| 肥城市| 崇文区| 崇阳县| 泽普县| 巧家县| 城固县| 策勒县| 遂宁市| 修武县| 周宁县| 罗源县| 沧州市| 汝城县| 淮滨县| 华亭县| 新安县| 泽普县| 甘谷县| 伊金霍洛旗| 西贡区| 汉沽区| 吉木乃县| 天气| 甘孜县| 英德市| 周宁县| 鄂州市| 桓仁| 安顺市| 曲松县| 锦屏县| 洛宁县| 杭锦后旗| 广饶县| 三亚市| 尖扎县| 南江县|