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
fix line 71 IndexError at Windows #39
Conversation
Thank you for bringing this up. Do you know why this error is happening? Is it because the WiFi does not have a password? |
In my case, the OS language is not English. I'm from korea, So I use Korean. Engilsh case: Key Content : !@#!$!@# Korean Case: 키 콘텐츠 : !@#!@# Different languages display differently. |
This is interesting. Does #25 happen to fix the issue you are facing? |
@sunrabbit123 The 'LANG' environment variable indicates the language/locale and encoding, where "C" is the default language setting, English. |
I understand. Thank you. But I think the solution is to make a big dictionary to get keywords that fit your language. Examples are below. keyword_dict = {
"en_US" : ["Key", "Key Contents"],
"ko_KR" : ["키" : "키 콘텐츠"]
.
.
.
}
key = keyword_dict["en_US"] |
Thank you for your suggestion. Could you try replacing the current def run_command(command):
env = os.environ.copy()
env["LANG"] = "C"
output, _ = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True).communicate()
return output.decode("utf-8").rstrip('\r\n') I think setting the locale would be a much better approach at fixing this issue as less code is needed to do so. |
LANG=C didn't work for me. The ploblem is netsh wlan show interfaces | findstr SSID
SSID : SK_WiFiGIGA42C0
BSSID : 00:23:aa:dc:42:c3
netsh wlan show profiles name="SK_WiFiGIGA42C0" key=clear | findstr 키
보안 키 : 있음
키 콘텐츠 : password but netsh wlan show profiles name="SK_WiFiGIGA42C0" key=clear | findstr Key
ERROR: Could not find password and We also found additional problems. Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python39\Scripts\wifi-password-script.py", line 33, in <module>
sys.exit(load_entry_point('wifi-password==1.0.7', 'console_scripts', 'wifi-password')())
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\wifi_password\wifi_password.py", line 124, in main
password = get_password(args.ssid)
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\wifi_password\wifi_password.py", line 78, in get_password
password = run_command(f"netsh wlan show profiles name=\"{ssid}\" key=clear | findstr 키").replace("\r", "")
File "C:\Users\user\AppData\Roaming\Python\Python39\site-packages\wifi_password\wifi_password.py", line 23, in run_command
return output.decode("utf-8").rstrip('\r\n')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 4: invalid start byte But the solution is simple. return output.decode("euc-kr") |
This means we would have to have a translation of the word "Key" in every language and then decode the output based on the system's language, right? I'll have to think about this because having a dictionary of the translation of all languages seems to be a waste of lines of code in my opinion. But if there is no other option, we'll have to stick with that then. |
I think so. However, rather than supporting all languages, I think it is better to provide basic support for English, but to provide opportunities for contributors to participate. You can know your own language with a simple Python script. The code is as follows: import locale
lang, _ = locale.getdefaultlocale()
print(lang) Windows supports approximately 106 languages. I think it would be good to use json. Thank you for reviewing my opinion. Because my method is not very efficient. |
Could you try this instead? def run_command(command):
env = os.environ.copy()
env["LC_ALL"] = "C"
output, _ = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True).communicate()
return output.decode("utf-8").rstrip('\r\n') Does this work? The change I made is |
Unfortunately, it doesn't work on Windows. However, I will find a way to change the output of the command to English |
|
run_command("chcp 437") It works very sexy. I think you can put this code at the beginning of the main function. def main():
run_command("chcp 437")
.
.
.
. |
After created the env variable you need to apply it for your subprocess. To do that you have to add env as parameters in subprocess.Popen() methods by adding def run_command(command):
env = os.environ.copy()
env["LC_ALL"] = "C"
output, _ = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True, env=env).communicate()
return output.decode("utf-8").rstrip('\r\n') |
I don't think that's a good idea because |
I agree with you, it is better to put it in the areas where Windows commands get executed. The only reason why I said to put it under the |
The language issue has been fixed in #45 |
I used this app
but I get this bug
That's why I added this.