tayfunulu / WiFiManager

WiFi manager for ESP8266 - ESP12 - ESP32 - micropython
MIT License
352 stars 105 forks source link

wifi password can't handle special chacter #37

Open Kugeleis opened 12 months ago

Kugeleis commented 12 months ago

I have a wifi password with & in it. WIFIManager is not able to connect to it. Error:

Trying to connect to mygreatwifi...
E (275725) wifi:sta is connecting, return error
Traceback (most recent call last):
  File "main.py", line 7, in <module>
  File "wifimgr.py", line 60, in get_connection
  File "wifimgr.py", line 317, in start
  File "wifimgr.py", line 200, in handle_configure
  File "wifimgr.py", line 88, in do_connect
OSError: Wifi Internal Error
MicroPython v1.21.0 on 2023-10-05; Generic ESP32 module with ESP32
ebolisa commented 12 months ago

try this:

# version 1.9 compatibility
    try:
        ssid = match.group(1).decode("utf-8").replace("%3F", "?").replace("%26", "&")
        password = match.group(2).decode("utf-8").replace("%3F", "?").replace("%26", "&")
    except Exception:
        ssid = match.group(1).replace("%3F", "?").replace("%26", "&")
        password = match.group(2).replace("%3F", "?").replace("%26", "&")
graham768 commented 3 months ago

@ebolisa's suggestion has been added as default behavior in the captive portal version of this awesome library

ebolisa commented 3 months ago

@ebolisa's suggestion has been added as default behavior in the captive portal version of this awesome library

Instead of adding all possible combination of characters, why not adding a simple routine to convert them all:

txt = "%3F,%26"

def decode_html(txt):
    dec = json.loads('"' + txt.replace('%', '\\u00') + '"')
    return dec

print(decode_html(txt))  --> ? & and etc.