Exemple #1
0
    def verifyCodeAutoByMyself(self,type=TYPE_LOGIN_NORMAL_WAY):
        try:
            urlInfo = loginUrls['other']['captcha'] if type == TYPE_LOGIN_OTHER_WAY else loginUrls['normal']['captcha']
            Log.v('正在获取验证码...')

            response = EasyHttp.send(urlInfo)
            address = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/image_captcha/'

            byte_stream = BytesIO(response)
            roiImg = Image.open(byte_stream)  # Image打开二进制流Byte字节流数据
            imgByteArr = BytesIO()  # 创建一个空的Bytes对象
            roiImg.save(imgByteArr, format='PNG')  # PNG就是图片格式,我试过换成JPG/jpg都不行
            imgByteArr = imgByteArr.getvalue()  # 这个就是保存的二进制流
            file_name = '1.jpg'
            file_path = address + file_name
            # 下面这一步只是本地测试, 可以直接把imgByteArr,当成参数上传到七牛云
            with open(file_path, "wb") as f:
                f.write(imgByteArr)

            from train.image_captcha import cut_image
            results = cut_image.cut_image(address,file_name)
            results = self.__indexTransCaptchaResults(results)

        except Exception as e:
            Log.w(e)
            return None, False
        return results, self._captchaAutoCheck(results)
Exemple #2
0
    def verifyCodeAutoByMyself(self):
        try:
            img_base64 = self.getCaptcha()
            address = os.path.dirname(
                os.path.dirname(
                    os.path.realpath(__file__))) + '/image_captcha/'

            byte_stream = BytesIO(img_base64)
            roiImg = Image.open(byte_stream)  # Image打开二进制流Byte字节流数据
            imgByteArr = BytesIO()  # 创建一个空的Bytes对象
            roiImg.save(imgByteArr, format='PNG')  # PNG就是图片格式,试过换成JPG/jpg都不行
            imgByteArr = imgByteArr.getvalue()  # 这个就是保存的二进制流
            file_name = '1.png'
            file_path = address + file_name
            # 下面这一步只是本地测试, 可以直接把imgByteArr,当成参数上传到七牛云
            with open(file_path, "wb") as f:
                f.write(imgByteArr)

            from train.image_captcha import cut_image
            results = cut_image.cut_image(address, file_name)
            results = self.__indexTransCaptchaResults(results)

        except Exception as e:
            return None, False
        return results, self._captchaAutoCheck(results)