Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't I output qrcode? #40

Closed
sunrabbit123 opened this issue Feb 6, 2021 · 6 comments
Closed

Why can't I output qrcode? #40

sunrabbit123 opened this issue Feb 6, 2021 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sunrabbit123
Copy link

image

Why not I get qrcode image?

I get only Unknown String

What is ploblem?

my OS is Windows 10
my python version is 3.9.0
my wifi-password version is 1.0.7

@sdushantha sdushantha added the bug Something isn't working label Feb 6, 2021
@sdushantha
Copy link
Owner

I am unsure of why this is happening. Maybe this is happening because your system's language is Latin a language. I don't use Windows so I unfortunately can't debug this error.

@sdushantha sdushantha added the help wanted Extra attention is needed label Feb 6, 2021
@sunrabbit123
Copy link
Author

My ststem language is korean

But this doesn't matter in code.

We need more examples.

@littlediobolic
Copy link
Contributor

This is likely affecting all windows boxes, at least it does on mine aswell. It likely has to do with the symbols the qrcode library is sending. I dont believe the windows terminal is UTF-8, therefore UTF-8 specific symbols dont display properly like they do on Mac and Linux. However in testing this I also noticed that outputting to image might also be broken? At least it is for me.

@sdushantha I think this might be an issue of the qrcode.print_tty() function. The next best thing in Windows might be their print_ascii function but I havent tested it

Confirmation of it being broken on mine:
wifi-password

Error when attempting to output to image file:
image-error

@sdushantha
Copy link
Owner

@sunrabbit123 @littlediobolic I think I found a solution to this issue.

In the beginning of the main function, could you add this code:

import colorama
colorama.init()

This will emulate support for ANSI escape sequences, which is needed in order to display the QR code.

If you don't have colorama installed, you'll have to install it through pip:

python3 -m pip install --user colorama

@sunrabbit123
Copy link
Author

Your solution works very sexy.

However, it would be better to write the phrase in generate_qr_code rather than main.

ex:

def generate_qr_code(ssid, password, image=False):
    # Source: https://git.io/JtLIv
    text = f"WIFI:T:WPA;S:{ssid};P:{password};;"

    qr = qrcode.QRCode(version=2,
                       error_correction=qrcode.constants.ERROR_CORRECT_L,
                       box_size=10,
                       border=4)
    qr.add_data(text)

    if image:
        file_name = ssid.replace(" ", "_") + ".png"
        img = qr.make_image()
        img.save(file_name)
        print(f"QR code has been saved to {file_name}")
        os.system(file_name)
    else:
        import colorama
        colorama.init()
        qr.make()
        qr.print_tty()

@sdushantha
Copy link
Owner

This issue has been fixed in a4cbf0d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants