firecat53 / networkmanager-dmenu

Control NetworkManager via dmenu
MIT License
806 stars 74 forks source link

UnicodeDecodeError in get_selection #39

Closed firecat53 closed 7 years ago

firecat53 commented 7 years ago
Traceback_ (most recent call last):
File "/usr/bin/networkmanager_dmenu", line 598, in <module> run()
File "/usr/bin/networkmanager_dmenu", line 593, in run gsm_actions, other_actions)
File "/usr/bin/networkmanager_dmenu", line 334, in get_selection
inp_bytes = "\n".join([str(i) for i in inp]).encode(ENC)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 152: ordinal not in range(128)

when trying to launch it.

So it looks like it finds this character "â" somewhere and poops out. Obviously, it shouldn't be able to find this character anywhere in networkmanager's menus, so it should be somewhere that allows for other input (Access point names perhaps). And indeed, after disabling WiFi, it managed to launch just fine. Looking at nm_applet, I can't find â in any of the AP names, but maybe networkmanager handles this by showing a different character? (a for example).

Edit: @xnick - (if this is the same one that opened the Arch AUR issue), any chance you can insert a debugging stop around line 325 and post the 'inp' variable with the failing value?

xnick commented 7 years ago

I'll try to reproduce it on Monday morning and do what you asked.

xnick commented 7 years ago

Hi, so there was no issue when I was able to test it last time. There didn't seem to be any network around with any special characters. I was able to reproduce it by creating a hotspot on my cell phone with that character in the name, and it failed to launch as expected. here is the inp array:

-> inp_bytes = "\n".join([str(i) for i in inp]).encode(ENC)
(Pdb) print inp 
['   Nexus 4\xc3\xa2            WPA2         ****', '   asdfgh public access  --           ****', '   eduroam              WPA2 802.1X  ****', '   sec-asdfgh             WPA2         *** ', "** asdfgh Wi-Fi Network   WPA2         *** ", '                        WPA1 WPA2    **  ', '   asdfgh            WPA1 WPA2    **  ', '   ', '   ASDFGH:VPN', '   ', '   Disable Wifi', '   Disable Networking', '   Launch Connection Manager', '   Delete a Connection']

with the breakpoint around line 333. The Nexus 4\xc3\xa2 AP is obviously the one in question. I have replaced the rest of the AP names because reasons.

Otherwise, it now fails with:

Traceback (most recent call last):
  File "/usr/bin/networkmanager_dmenu", line 598, in <module>
    run()
  File "/usr/bin/networkmanager_dmenu", line 593, in run
    gsm_actions, other_actions)
  File "/usr/bin/networkmanager_dmenu", line 334, in get_selection
    inp_bytes = "\n".join([str(i) for i in inp]).encode(ENC)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128)

So apparently I was wrong about which character was the issue, though the issue remains.

firecat53 commented 7 years ago

Hmm. I'm afraid I can't reproduce this. It works correctly when I setup a hotspot on my phone named "Nexus 4â". It displayed correctly in dmenu (and Rofi) and I was able to connect to it with no issue.

Perhaps the language or encoding on your system is set differently? I'm using urxvt as my terminal on Archlinux. LANG=en_US.UTF-8 and TERM=screen-256color.

Are you using a different language or encoding? Any other language or encoding setup you have that might be different than a default setup?

xnick commented 7 years ago

So..... It turns out that it was indeed an issue on my side.

I had created a symlink in /usr/local/bin/python to python2.7 at some point in time that I apparently forgot about, which didn't prove to be an issue till now. So I was running your script under python 2.7 which uses ascii internally by default, resulting in the error.

Anyway, thanks a lot for your help, and sorry for wasting your time.

firecat53 commented 7 years ago

No time wasted! It's supposed to work with 2.7 as well... Which I failed to test yesterday... So I need to figure out how to fix that!

firecat53 commented 7 years ago

@xnick Hopefully this fixes the problem for you. Please test as you can and make sure I didn't break anything else!

xnick commented 7 years ago

Tested. All good in both 2.7&3.

zerinoid commented 4 years ago

Hello, sorry to open this old thread. I'm only able to run it with python3.6, on 2.7 it gives me:

Traceback (most recent call last):
  File "/usr/local/bin/networkmanager_dmenu", line 689, in <module>
    run()
  File "/usr/local/bin/networkmanager_dmenu", line 662, in run
    ap_actions = create_ap_actions(*create_ap_list(adapter, active))
  File "/usr/local/bin/networkmanager_dmenu", line 295, in create_ap_actions
    max_len_sec, bars)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)
firecat53 commented 4 years ago

I ended python 2 support back in November. See README note.