Is Anyone Else Experiencing Issues with Python Packages?

This topic was automatically generated from Slack. You can find the original thread here.

Getting this error after jumping back into a workflow that worked perfectly yesterday. Is anyone else having issues with Python packages?

could you do me a favor and test this once more? We just shipped a fix for this bug

if not, can you share the exact code you’re running so I can take a look?

Hey No luck following deploy. Still throwing an error.

from reportlab.lib.pagesizes import portrait, mm
from reportlab.pdfgen import canvas
from datetime import datetime
from io import BytesIO
import base64
import qrcode
from reportlab.lib.utils import ImageReader

def generate_qr_codes(qr_code_values, qr_code_size=200):
    qr_codes = []
    for value in qr_code_values:
        qr = qrcode.QRCode(
            version=1,  # QR code version (adjust as needed)
            error_correction=qrcode.constants.ERROR_CORRECT_L,  # Error correction level
            box_size=10,  # Size of each QR code module
            border=1,  # Border around the QR code
        )
        qr.add_data(value)
        qr.make(fit=True)
        
        # Generate the QR code as an image with higher resolution
        qr_img = qr.make_image(fill_color="black", back_color="white", size=(qr_code_size, qr_code_size))
        qr_codes.append(qr_img)
    return qr_codes

def generate_pdf_with_qr_codes(qr_codes, expiry_month):
    buffer = BytesIO()
    c = canvas.Canvas(buffer, pagesize=(23 ** mm, 23 ** mm))

    for qr_code in qr_codes:
        barcode_size = 20 ** mm
        x_position = (23 ** mm - barcode_size) / 2
        y_position = 23 ** mm - barcode_size

        # Create a temporary file to save the image with the desired size
        with BytesIO() as temp_image_buffer:
            qr_code.save(temp_image_buffer, format="PNG")

            # Use ImageReader to read the image from the buffer
            temp_image_buffer.seek(0)
            img_reader = ImageReader(temp_image_buffer)

            # Draw the QR code image centered within the canvas and scale it down
            c.drawImage(img_reader, x_position, y_position, width=barcode_size, height=barcode_size, preserveAspectRatio=True)

        # Draw the "Expiry: MM/YY" text centered below the QR code with a font size of 8pt
        c.setFont("Helvetica", 8)
        text = f"Expiry: {expiry_month}"
        text_width = c.stringWidth(text, "Helvetica", 8)
        text_x = (23 ** mm - text_width) / 2
        text_y = y_position - 2 * mm
        c.drawString(text_x, text_y, text)
        
        c.showPage()

    c.save()

    # Get the PDF data and encode it in base64
    pdf_data = buffer.getvalue()
    pdf_base64 = base64.b64encode(pdf_data).decode('utf-8')
    buffer.close()

    return pdf_base64

# Usage example
if __name__ == "__main__":
    qr_code_values = ["Value1", "Value2", "Value3"]  # Replace with your QR code values
    expiry_month = "10/25"
    qr_code_size = 400  # Adjust the size as needed
    
    qr_codes = generate_qr_codes(qr_code_values, qr_code_size)
    pdf_base64 = generate_pdf_with_qr_codes(qr_codes, expiry_month)

    # Print or return pdf_base64 as needed
    print(pdf_base64)

Thanks. We identified another issue and we’re working to correct it. I’ll let you know when that’s out

apologies for the back and forth, can you try it once more? Your code ran for me and I’d like to see if that works in your workflow.

Working now! Cheers!

glad to hear, thanks for reporting