QR Code scanning and generation. When I go to scan the QR code I want it to display some plain text information, instead I am shown “no usable info”

So I am working on a python script that generates a QR code that contains info, which are email, name, id, and a website to redirect to when scanned. I successfully created the generation of the QR code here:

def generate_qr_code_redirect_and_id(name, email, redirect_url):
    # Generate ID
    id = generate_id(name, email)
    
    # Construct data for QR code including the GIF URL
    data = f"ID: {id}nName: {name}nEmail: {email}nRedirectURL: {redirect_url}nGIF: https://gifdb.com/images/high/spongebob-squarepants-done-and-done-2de4g1978uus7pp6.gif"
    
    # Generate QR code
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_M,
        box_size=10,
        border=4,
    )
    qr.add_data(data)
    qr.make(fit=True)
    qr_image = qr.make_image(fill_color="black", back_color="white")
    
    # Convert image to bytes
    qr_buffer = BytesIO()
    qr_image.save(qr_buffer, format='PNG')
    qr_image_data = qr_buffer.getvalue()
    
    return id, qr_image_data

I also got the data to be uploaded to a MongoDB cluster and I also got it saved automatically in a csv file.

The problem is when I go scan the QR code, it shows on my phone no usable information.
Here is the rest of the code (all imports done):

def generate_id(name, email):
    # Generate an ID using email and name
    data = f"{name}_{email}"
    hashed_data = hashlib.sha256(data.encode('utf-8')).hexdigest()
    return hashed_data


def generate_qr_code_redirect_and_id(name, email, redirect_url):
    # Generate ID
    id = generate_id(name, email)
    
    # Construct data for QR code including the GIF URL
    data = f"ID: {id}nName: {name}nEmail: {email}nRedirectURL: {redirect_url}nGIF: https://gifdb.com/images/high/spongebob-squarepants-done-and-done-2de4g1978uus7pp6.gif"
    
    # Generate QR code
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_M,
        box_size=10,
        border=4,
    )
    qr.add_data(data)
    qr.make(fit=True)
    qr_image = qr.make_image(fill_color="black", back_color="white")
    
    # Convert image to bytes
    qr_buffer = BytesIO()
    qr_image.save(qr_buffer, format='PNG')
    qr_image_data = qr_buffer.getvalue()
    
    return id, qr_image_data


def upload_to_mongodb_and_csv(id, name, email, redirect_url):
    # Connect to MongoDB
    client = MongoClient(
        'mongo connection string hidden for privacy'
    )
    
    # Select database and collection
    db = client['QRCode-Scans']
    collection = db['People-Who-Scanned']
    
    # Create document to insert
    document = {
        'id': id,
        'name': name,
        'email': email,
        'redirect_url': redirect_url
        # Add more fields as needed
    }
    
    # Insert document into collection
    collection.insert_one(document)
    
    # Write data to CSV file
    with open('data.csv', mode='a', newline='') as file:
        writer = csv.writer(file)
        writer.writerow([id, name, email, redirect_url])



def send_email_with_qr_code(sender_email, sender_password, recipient_email, qr_code_image_data, id, name, email, redirect_url):
    msg = MIMEMultipart()
    msg['From'] = sender_email
    msg['To'] = recipient_email
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = "Your QR Code"
    
    # Email body
    body = f"Hello,nnHere is your QR code along with the details:nnName: {name}nEmail: {email}nRedirect URL: {redirect_url}nnBest regards,nName"
    msg.attach(MIMEText(body))
    
    # Attach QR code image
    image = MIMEImage(qr_code_image_data)
    image.add_header('Content-Disposition', 'attachment', filename="qr_code.png")
    msg.attach(image)
    
    # Connect to SMTP server and send email
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(sender_email, sender_password)
    server.send_message(msg)
    server.quit()


def read_recipients_from_csv(csv_file):
    recipients = []
    with open(csv_file, mode='r', newline='') as file:
        reader = csv.reader(file)
        next(reader)  # Skip the header row
        for row in reader:
            if len(row) >= 2:
                recipients.append({"name": row[0], "email": row[1]})
            else:
                print(f"Issue with row: {row}")  # Print rows with missing data
    return recipients

# Example usage:

# Path to the CSV file containing recipient information
csv_file_path = "input.csv"
# Read recipients from the CSV file
recipients = read_recipients_from_csv(csv_file_path)
sender_email = "an email hidden for privacy"
sender_password = "app access code hidden for privacy"
# recipients = [
#     # {"name": "name hidden for privacy", "email": "an email hidden for privacy"},
#     # # Add more recipients as needed
# ]

for recipient in recipients:
    name = recipient["name"]
    email = recipient["email"]
    
    # Generate QR code
    id, qr_code_image = generate_qr_code_redirect_and_id(name, email, "https://www.google.com")
    
    # Upload data to MongoDB and CSV
    upload_to_mongodb_and_csv(id, name, email, "https://www.google.com")

    # Send email with QR code image data and details
    send_email_with_qr_code(sender_email, sender_password, email, qr_code_image, id, name, email, "https://www.google.com")

Here is the QR code for reference:

enter image description here

I tried adjusting the ERROR_CORRECT_M to different levels, didn’t work. I just want it to display some text that shows the email and name that are encoded within the QR code. It is probably formatted some wrong way, if it is then I have no clue how to fix and what is wrong with the format exactly.

I expected it show me a plain text of the name and email.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật