From 46839afa8e27f58cd245382f27267dae8d6c9b30 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Wed, 26 Apr 2017 23:40:06 +0800 Subject: [PATCH] fix captcha py3 compatible --- utils/captcha/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/captcha/__init__.py b/utils/captcha/__init__.py index f1754a4..ee3fe25 100644 --- a/utils/captcha/__init__.py +++ b/utils/captcha/__init__.py @@ -18,7 +18,7 @@ import os import time import random -from io import StringIO +from io import BytesIO from django.http import HttpResponse from PIL import Image, ImageDraw, ImageFont @@ -86,7 +86,7 @@ class Captcha(object): # 随机化字符之间的距离 字符粘连可以降低识别率 x += font_size * random.randrange(6, 8) / 10 - buf = StringIO() + buf = BytesIO() image.save(buf, "gif") self.django_request.session[self.session_key] = "".join(code)