基于Gunicorn / Flask的QRcode图像错误

时间:2018-02-22 08:58:57

标签: python flask qr-code gunicorn

我使用QRCode在烧瓶项目中生成密码。代码很简单

# works for werkzerg, not for gunicorn    
@expose('/qrcode/<string:text>')
@has_access
def qrcode(self, text):
    qr = qrcode.QRCode(
        version=4,
        error_correction=qrcode.constants.ERROR_CORRECT_H,
        box_size=10,
        border=1)
    qr.add_data(text)
    img = qr.make_image()

    byte_io = BytesIO()
    img.save(byte_io, 'PNG')
    byte_io.seek(0)

    return send_file(byte_io, mimetype="image/png")

flask-appbuilder项目基于flask框架,不同的装饰器就像暴露,而不是路由。

这个代码可以和Wergzeug一起使用,但是当我在Gunicorn的生产服务器上运行时。它抛出以下错误:

2018-02-22 16:27:52,377:ERROR:gunicorn.error:Error handling request
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gunicorn/workers/sync.py", line 102, in handle_request
    resp.write_file(respiter)
  File "/usr/lib/pymodules/python2.7/gunicorn/http/wsgi.py", line 285, in write_file
    fileno = respiter.filelike.fileno()
UnsupportedOperation: fileno

我猜send_file和gunicorn之间存在一些问题。是否有人有类似的问题和解决方案?

1 个答案:

答案 0 :(得分:1)

用pip升级后,这是Gunicorn中的一个错误。

sudo pip install -U gunicorn

该代码现在与gunicorn合作。