lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.25k stars 660 forks source link

Python 3.12: 'WindowsPath' object has no attribute 'write' #344

Open zc-devs opened 9 months ago

zc-devs commented 9 months ago

Next code doesn't work anymore:

qr = qrcode.make("some data")
qr.save(path.with_name("qr.png"))

Worked fine on Python 3.10.

Stacktrace:

Traceback (most recent call last):
    gen_qr(,
  File "C:\Users\User\test\qr_gen.py", line 66, in gen_qr
    qr.save(path.with_name("qr.png"))
  File "C:\Program Files\Python312\Lib\site-packages\qrcode\image\pure.py", line 28, in save
    self._img.write(stream, self.rows_iter())
  File "C:\Program Files\Python312\Lib\site-packages\png.py", line 668, in write
    nrows = self.write_passes(outfile, check_rows(rows))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\png.py", line 703, in write_passes
    return self.write_packed(outfile, rows)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\png.py", line 723, in write_packed
    self.write_preamble(outfile)
  File "C:\Program Files\Python312\Lib\site-packages\png.py", line 771, in write_preamble
    outfile.write(signature)
    ^^^^^^^^^^^^^
AttributeError: 'WindowsPath' object has no attribute 'write'. Did you mean: 'drive'?

Environment:

JoeanAmier commented 8 months ago

qr = qrcode.make("some data") qr.save(str(path.with_name("qr.png")))

zc-devs commented 8 months ago

It works! Thank you, @JoeanAmier!