lincolnloop / python-qrcode

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

AttributeError: 'SvgPathImage' object has no attribute 'mode' #356

Open nabelekt opened 7 months ago

nabelekt commented 7 months ago

I am just learning how to use this python module, so I may not be using it as intended, but it does seem like some error is not being handled appropriately. Here's my code:

import qrcode
import qrcode.image.svg

# Documentation: https://github.com/lincolnloop/python-qrcode
qr = qrcode.QRCode(
    version=None,  # Controls size of QR code
    error_correction=qrcode.constants.ERROR_CORRECT_M,  # Error correction level
    box_size=10,  # How many pixels per box
    border=4,  # Border size; min is 10 per spec
)

qr.add_data("something interesting")
qr.make(fit=True)

factory = factory = qrcode.image.svg.SvgPathImage
img = qr.make_image(image_factory=factory,
                    fill_color="black",
                    back_color="white",
                    module_drawer=qrcode.image.styles.moduledrawers.HorizontalBarsDrawer())

Here's the error I am getting:

Traceback (most recent call last):
  File "/home/thomas/repos/utilities/commissioning/qr_test.py", line 22, in <module>
    img = qr.make_image(image_factory=factory,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/main.py", line 365, in make_image
    im = image_factory(
         ^^^^^^^^^^^^^^
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/svg.py", line 145, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/svg.py", line 27, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 139, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 31, in __init__
    self.init_new_image()
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 150, in init_new_image
    self.module_drawer.initialize(img=self)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/styles/moduledrawers/pil.py", line 232, in initialize
    self.setup_edges()
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/styles/moduledrawers/pil.py", line 235, in setup_edges
    mode = self.img.mode
           ^^^^^^^^^^^^^
AttributeError: 'SvgPathImage' object has no attribute 'mode'

Thanks!