lincolnloop / python-qrcode

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

The Bug of Http url mixed Chinese character #193

Closed RyanLiuF closed 3 years ago

RyanLiuF commented 4 years ago
import qrcode
qr = qrcode.QRCode(   
  version=1,   
  error_correction=qrcode.constants.ERROR_CORRECT_L,   
  box_size=20,   
  border=4, 
) 
qr.add_data('http://127.0.0.1/file/economic/现代方法.pdf') 
qr.make(fit=True) 
img = qr.make_image()
img.save('test.png')

If the url is 'http://127.0.0.1/file/economic/现代方法.pdf', then the scanned image data is 'http://127.0.0.1/file/economic/.pdf'. But if the url is 'http:/127.0.0.1/file/economic/现代方法.pdf', the result is OK. Please fixed it.

heuer commented 4 years ago

Is the missing slash after the http scheme in the 2nd URL intentional?

Using your code above results into the following QR Code test

Decoding seems to be fine test-decoded

RyanLiuF commented 4 years ago

But I use the wechat app to scan the image , the result is "http://127.0.0.1/file/economic/.pdf". Seems that the app makes mistake ??

nayuki commented 4 years ago

I believe you are not allowed to put Unicode characters into URLs. You should UTF-8 encode them and then percent-encode them, like this: http://127.0.0.1/file/economic/%E7%8E%B0%E4%BB%A3%E6%96%B9%E6%B3%95.pdf

johann-lau commented 3 years ago

I am experiencing a similar issue with a Discord Bot URL: https://discord.com/oauth2/authorize?client_id=123456&permissions=0&scope=bot%20applications.commands I tried scanning with a full-fledged GUI scanner as well as another Python library, but none of them gave me a result. They couldn't even detect the QR Code in the image.

nayuki commented 3 years ago

@johann-lau Please post a screenshot or picture of the QR Code that you are having problems with.

Also, it's not clear that your problem is related to this existing thread, which is about Chinese/Unicode characters in a URL.