cannot identify image file

最近在写毕业论文,爬取数据但是遇到了cannot identify image file错误

#有关的一段代码
import requests
import json
import urllib.request
import pytesseract#OCR识别库
from PIL import Image
# 发送GET请求下载验证码图片
captcha_response = requests.get(url, headers=headers, cookies=cookie)
 
if captcha_response.status_code == 200:
    with open('captcha.png', 'wb') as f:
        f.write(captcha_response.content)
        print("下载成功")
        try:
            image = Image.open('D:\\pycharm项目\\demo\\captcha.png')
            img = image.convert('L')#灰度处理
            # 使用pytesseract进行OCR处理
            text = pytesseract.image_to_string(img)
            print(text)
        except Exception as e:
            print("发生错误:", e)#打印错误信息
 
 
else:
    print("下载失败,状态码为", captcha_response.status_code)

模拟登陆的时候遇到了验证码,将验证码的地址赋值然后直接进行灰度处理进行读取

然后运行遇到了

登录失败,HTTP状态码:200
下载成功
发生错误: cannot identify image file 'D:\\pycharm项目\\demo\\captcha.png'

来个大佬help我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值