awkman/pywifi

UnicodeEncodeError

Github-User-Rey opened this issue · 3 comments

SSID cannot be displayed with Chinese characters

I've written this part of code to fix this problem, hope it helps :)
(I'll pull request to fix this problem in "wifiutil.py" soon)
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
iface.scan()
result=iface.scan_results()
for i in range(len(result)):
SSID = result[i].ssids = SSID.encode()
cnt = 0
res = 0
lst = []
name = ""
for char in SSID :
if (33<=ord(char)<=126) :
name = name + char
else :
cnt = cnt + 1
now = int(str(bin(ord(char)))[2:6],2)
now1 = int(str(bin(ord(char)))[6:10], 2)
res = res + now * 16 + now1
lst.append(res)
res = 0
if cnt == 3 :
name = name +bytes(lst).decode('utf-8','ignore')
lst = []
res = 0
cnt = 0
print(name)

@Github-User-Rey
After getting the ssid you could use the following code to print the ssid in chinese in your terminal
print(ssid.encode('raw_unicode_escape').decode())

It still doesn't work with above two methods. @awkman