python3.9 pix.set_pixel has something wrong in c.append( ord(i)) (original) (raw)

Description of the bug

python3.9 pix.set_pixel(pos[0], pos[1], (255, 255, 255))
with the error

/lib/python3.9/site-packages/fitz/init.py", line 10131, in set_pixel c.append( ord(i))

How to reproduce the bug

The code is like this, has some wrong with python3.9, but it works with python3.7

pdf_file = fitz.open(input_pdf_path)

    for page_no, page in enumerate(pdf_file):
        zoom_x = 4.0
        zoom_y = 4.0
        matrix = fitz.Matrix(zoom_x, zoom_y)
        pix = page.get_pixmap(matrix=matrix)

        for pos in product(range(pix.width), range(pix.height)):
            if sum(pix.pixel(pos[0], pos[1])) >= 600:
                pix.set_pixel(pos[0], pos[1], (255, 255, 255))

PyMuPDF version

1.23.12

Operating system

MacOS

Python version

3.9