Ejemplo n.º 1
0
def graph_captcha():
    text, image =Captcha.gene_graph_captcha()
    rds.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 2
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    zlcache.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, 'png')  # 指定格式为png
    out.seek(0)  # 把指针指到开始位置
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 3
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    zlcache.set(text.lower(), text.lower())  # 存储到memcached
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)  # 将文件指针设置为0
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 4
0
def get_captcha():
    text, image = Captcha.gene_graph_captcha()
    memcaches.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 5
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    mbcache.set(text.lower(), text.lower())
    out = BytesIO()  # 二进制流对象
    image.save(out, 'png')  # 保存在out中
    out.seek(0)  # 文件流的指针放在0位置
    resp = make_response(out.read())  # 读出来
    resp.content_type = 'image/png'  # 指定数据类型
    return resp
Ejemplo n.º 6
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    zlcache.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, "png")
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = "image/png"
    return resp
Ejemplo n.º 7
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    xcache.set(text.lower(),text.lower()) #图片验证码这里,不好设置一个唯一的key,索性直接也用验证码的值作为key
    return resp
Ejemplo n.º 8
0
def gene_captcha():
    text, image = Captcha.gene_graph_captcha()
    cms_memcache.set('captcha', text, timeout=600)
    print('captcha:', cms_memcache.get('captcha'))
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 9
0
def graph_captcha():
    #调用得到验证码
    text, image = Captcha.gene_graph_captcha()
    #bytesIO二进制流
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
def graph_captcha():
    captcha, image = Captcha.gene_graph_captcha()
    print('图形验证码是:', captcha)  # 打印出图形验证码
    zlcache.set(captcha.lower(), captcha.lower())  # 把验证码添加到memcached缓存中
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 11
0
def graph_captcha():
    text,image = Captcha.gene_graph_captcha()
    print('本次的图形验证码是:%s' %text)
    zlcache.set(text.lower(),text.lower())
    out = BytesIO()
    image.save(out,'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 12
0
def capture():
    text, image = Captcha.gene_graph_captcha()
    # 存入memcache缓存
    bbs_cache.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)

    respon = make_response(out.read())
    respon.content_type = 'imge/png'
    return respon
Ejemplo n.º 13
0
def graph_captcha():
    # 获取验证码
    text, image = Captcha.gene_graph_captcha()
    zlcache.set(text.lower(), text.lower())
    # BytesIO: 自截留
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)  # 将指针返回开头,save过后指针位置在最后
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 14
0
def graph_captcha():
    #获取验证码
    text,image=Captcha.gene_graph_captcha()
    zlcache.set(text.replace(" ","").lower(),text.replace(" ","").lower()) #text.replece(" ","")去掉空格
    #ByteIo:字节流 (必须用二进制流的形式才能在网络上传输) 保存在内存中
    out=BytesIO()
    image.save(out,'png') #保存的格式是png
    out.seek(0) #把文件流的指针放到最开始的位置
    resp=make_response(out.read()) #创建response对象
    resp.content_type='image/png'#response的数据类型
    return resp
Ejemplo n.º 15
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    print('存的key为:', text.lower())
    cache.set(text.lower(), text.lower())
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    print('取出的值为:', cache.get(text.lower()))
    return resp
Ejemplo n.º 16
0
def graph_captcha():
    # 获取验证码
    text, image = Captcha.gene_graph_captcha()
    zlcache.set('graph_captcha', text)
    # BytesIO 自截留,二进制流数据
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 17
0
def graph_captcha():
    #获取验证码
    text, image = Captcha.gene_graph_captcha()
    zlcache.set(text.lower(),
                text.lower())  #图形验证吗存储到memcached,key和value都是验证码本身并变为小写存储
    #字节流
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 18
0
def graph_capture():
    text, image = Captcha.gene_graph_captcha()
    temp = json.dumps(''.join(text).lower())
    with open('temp.json', 'w') as f:
        f.write(temp)
    #  验证码图片以二进制形式写入内存,防止图片都放在文件夹中,占用磁盘空间
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 19
0
def gene_captcha():
    text,image = Captcha.gene_graph_captcha()
    type = request.args.get('type')
    if type:
        session[type] = text
        print(type,text)
    out = BytesIO()
    image.save(out,'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 20
0
def graph_captcha():
    # 获取到生成的验证码的图片
    text, image = Captcha.gene_graph_captcha()
    # 存储图形验证码到内存
    cache.set(text.lower(), text.lower())
    # 将图片转换成二进制流的形式,使用make_response包装成浏览器可以识别的图片
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp  # 返回一张二进制表示的图片
Ejemplo n.º 21
0
def image_captcha(request):
    text, image = Captcha.gene_graph_captcha()
    # 图片是一个流数据,也就是存到一个管道中,不像字符串可以用容器来保存
    out = BytesIO()  # 创建一个管道
    image.save(out, 'png')  # 保存图片的流数据
    # 读取的时候从0开始,为了防止读不到数据,指针一定要回0
    out.seek(0)  # 指针回0
    # 把图片返回到浏览器上,通过response对象返回
    response = HttpResponse(content_type='image/png')
    response.write(out.read())
    response['Content-length'] = out.tell()
    cache.set(text.lower(), text.lower(), 5 * 60)
    return response
Ejemplo n.º 22
0
def graph_captcha():
    #调用得到验证码
    text, image = Captcha.gene_graph_captcha()
    #bytesIO二进制流
    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    print('前端生成的图形验证码是', text.lower())
    landicache.set(text.lower(), text.lower())
    print('后端生成的图形验证码', landicache.get(text.lower()))
    return resp
Ejemplo n.º 23
0
Archivo: views.py Proyecto: CZ2016/zedd
def graph_captcha():
    # 获取验证码,在浏览器中不能直接返回image对象,需要转化为二进制流的数据,才能识别
    text,image=Captcha.gene_graph_captcha()
    zlache.set(text.lower(),text.lower(),timeout=120)
    # print(zlache.get(text.lower()))
    # BytesIO:自截留
    out=BytesIO()
    image.save(out,'png')
    # 文件流的指针要放到开始的位置
    out.seek(0)
    resp=make_response(out.read())
    resp.content_type='image/png'
    return resp
Ejemplo n.º 24
0
def graph_captcha():
    # 获取验证码
    text,image=Captcha.gene_graph_captcha()
    print('图形验证码:%s'%text)
    zlcache.set(text.lower(),text.lower())
    # BytesIO:字节流  创建二进制流对象
    out=BytesIO()
    image.save(out,'png')
    # 将文件指针放到最开始位置,方便下面读取.如果指针在最末尾,读取不到文件
    out.seek(0)
    resp=make_response(out.read())
    resp.content_type='image/png'
    # resp.content_type='application/octet-stream'
    return resp
Ejemplo n.º 25
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    out = BytesIO()
    # with open("{}.png".format(image),'rb') as f:
    #     image = f.read()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    # print(resp)
    # resp = Response(resp,mimetype="image/png")
    # resp.context_type = 'image/png'
    resp.headers['Content-Type'] = 'image/jpg'

    return resp
Ejemplo n.º 26
0
def graph_captcha():
    """获取图形验证码"""
    # 获取验证码
    text, image = Captcha.gene_graph_captcha()
    # 存储验证码, 转换为小写
    ycache.set(text.lower(), text.lower())
    # 字节流
    out = BytesIO()
    image.save(out, 'png')
    # 把文件指针设置到文件开头处,否则下次文件读取的时候无法读取
    out.seek(0)
    resp = make_response(out.read())
    resp.content_type = 'image/png'
    return resp
Ejemplo n.º 27
0
def graph_captcha():
    try:
        text, image = Captcha.gene_graph_captcha()
        lgcache.redis_set(text.lower(), text.lower())
        # BytesIO 字节流
        out = BytesIO()
        # 把图片保存在字节流中  并制定格式png
        image.save(out, 'png')
        # 文件流指针
        out.seek(0)
        resp = make_response(out.read())
        resp.content_type = 'image/png'
    except:
        return graph_captcha()
    return resp
Ejemplo n.º 28
0
def graph_captcha():
    text, image = Captcha.gene_graph_captcha()
    #存储图形验证码到服务器
    zlcache.set(text.lower(),text.lower())

    out = BytesIO()
    image.save(out, 'png')
    out.seek(0)
    resp = make_response(out.read())
    # print(resp)
    # resp = Response(resp,mimetype="image/png")
    # resp.context_type = 'image/png'
    resp.headers['Content-Type'] = 'image/jpg'

    return resp
Ejemplo n.º 29
0
def graph_captcha():
    # 获取图形验证码
    text, image = Captcha.gene_graph_captcha()
    try:
        se = current_app.redis
        se.setex('image_code', 60 * 5, text)
    except RedisError as e:
        print(e)
        return 'redis问题'
    # bytest 字节流
    out = BytesIO()  # 图片转成二进制再发送发给浏览器显示
    image.save(out, 'png')  # 图片保存对象和类型
    out.seek(0)  # 将文件指针移动到文件首,保存后指针位于末尾
    resp = make_response(out.read())  # 将数据读取后添加到response返回
    resp.content_type = 'image/png'  # 指定文件类型
    return resp
Ejemplo n.º 30
0
def img_captcha(request):
    text,image = Captcha.gene_graph_captcha()
    # 将生成的验证码数字保存到memcache
    dxcache.set(text.lower(),text.lower())
    # BytesIO相当于一个管道,用来存放图片的流数据
    out = BytesIO()
    # 调用image的save方法,将图片保存在ByteIO中,
    image.save(out,'png')
    # 指针移动到开头
    out.seek(0)
    # HttpResponse对象
    response = HttpResponse(content_type='image/png')
    # 将ByteIO对象取出,写入到response里面
    response.write(out.read())
    response['Content-length'] = out.tell()
    return response
Ejemplo n.º 31
0
def graph_captcha():
    try:
        text, image = Captcha.gene_graph_captcha()
        print('发送的图形验证码:{}'.format(text))
        clcache.save_captcha(text.lower(), text)
        # 处理图片二进制流的传输
        out = BytesIO()
        # 把图片保存到字节流中,并指定格式为png
        image.save(out, 'png')
        # 指定文件流指针,从文件最开始开始读
        out.seek(0)
        # 将字节流包装到Response对象中,返回前端
        resp = make_response(out.read())
        resp.content_type = 'image/png'
    except:
        return graph_captcha()

    return resp