0

I'm using PyQRCode [0] to generate a QR in PNG format under Python 2.7.6.

When I try to write a file on disk using all works ok:

import pyqrcode
from io import BytesIO
qr = pyqrcode.create("my qr string", mode='binary', version=7)
qr.png("myqr.png", scale=4)

But when I try to use a io stream using this code:

import pyqrcode
from io import BytesIO
qr = pyqrcode.create("my qr string", mode='binary', version=7)
f=BytesIO()
qr.png(f, scale=4)
f.getvalue()

I get on the f.getvalue() line:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: I/O operation on closed file.

The PyQRCode documentation says that the file parameter could be a writeable stream.

I tried hard to debug this but I can't find where the stream is being closed and there is not any .close() statement for the stream. [1]

[0] https://pypi.python.org/pypi/PyQRCode

[1] http://pythonhosted.org//PyQRCode/_modules/pyqrcode.html#QRCode.png

4

1 回答 1

1

这是 PyQRCode 中的一个错误,Github 存储库中有一个 PR(尚未合并)可以解决此问题:

https://github.com/mnooner256/pyqrcode/pull/6

于 2015-02-05T02:53:24.947 回答