Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Invalid url thai language
-
Hello
Help me pleaseimport webbrowser link1 = 'เราชนะ' link2= 'google' thaiUrl = "https://www.{}.com".format(link1) EnUrl = "https://www.{}.com".format(link2)
webbrowser.open(EnUrl)—>>> ok
webbrowser.open(thaiUrl) —>>> invalid url ,how to fix 🙏🏻🙏🏻
-
try this:
thaiUrl = "https://www.{}.com".format(link1.encode('idna').decode('latin1'))
reason: urls are not actually allowed to be in Unicode, they technically must be latin1. However, idna is a method of displaying specially coded latin1 urls as Unicode. The .encode('idna') creates an idna encoded url. However, webbrowser expects a string (which must contain only latin1 characters!), not bytes, hence the decode back to latin1.
There may be a cleaner way to do this, but the above should work.
-
Thank you🙏🏻🙏🏻🙏🏻🙏🏻👍👍