awkman / pywifi

A cross-platform module for manipulating WiFi devices.
MIT License
447 stars 154 forks source link

UnicodeEncodeError #25

Open Github-User-Rey opened 6 years ago

Github-User-Rey commented 6 years ago

SSID cannot be displayed with Chinese characters

hktkqj commented 5 years ago

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)

awkman commented 5 years ago

@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())

spwpun commented 5 years ago

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