wireless icon indicating copy to clipboard operation
wireless copied to clipboard

Can't connect to ssid with spaces?

Open scottdito opened this issue 8 years ago • 6 comments

Hi,

I am running this package on Ubuntu 16.04 and Python 2.7.11+. It runs great until I try to connect to a network with a space in its ssid, i.e. ssid = "The Name".

Is this a known issue with this package or should I start looking at other causes?

Thanks for the help!

scottdito avatar Jul 18 '16 19:07 scottdito

It worked for me, however this was using a previous version - this may have seen work since then; Manually connecting to the ssid works, tho?

deepbrook avatar Jul 19 '16 20:07 deepbrook

I can connect to the ssid with the space in its name through the GUI, meaning the drop down list from my wifi icon, but when I try it in the Python command line using Wireless v0.3.2 I can't get to it. It returns "False".

An interesting caveat: when I connect to it through the GUI then use the Wireless.current() command in the package, I get "u'The Name" on my Macbook, but just "u'The" on my Ubuntu machine.

It makes me think that it does have something to do with spaces...

scottdito avatar Jul 19 '16 21:07 scottdito

Yes, I think the issue originates from line 276 of wireless.py:

    # the current network is in the first column
    for line in response.splitlines():
            if len(line) > 0:
    return line.split()[0]

This may be due to encoding, albeit I am not sure about this - since windows, mac and linux systems have different defaults, it may be possible that Mac encodes whitespaces differently, hence the line.split()[0] doesn't find a whitespace on mac, but since Linux encodes using UTF-8 by default, it may cause it drop Name from The Name.

Since I don't own a Mac, could you check your default encoding? you can do this like so (using a python interpreter)

import sys
sys.getdefaultencoding()  # Out of curiosity, check the default file encoding
sys.stdout.encoding  # This should be relevant, since the package uses a pipe to generate the file

In either case, this is an issue for linux users, that should be addressed - especially since Josh already uses subprocess, he could use grep and awk to get the first column other than by splitting lines - given that columns aren't seperated by \t characters (which I don't know).

deepbrook avatar Jul 20 '16 05:07 deepbrook

Ah, nevermind - I just saw that decode() (which defaults to 'utf-8') is run on subprocess.popen()'s returned value in def cmd(). It shouldn't be encoding related then.

deepbrook avatar Jul 20 '16 06:07 deepbrook

I haven't been able to go through the code as much as I'd like, but an interesting tidbit: when I use the nmcli and networksetup commands in the terminal, I have no problem connecting to the ssid with spaces in it. I use those commands pretty much verbatim how they're used in Wireless.py and I don't have any trouble.

I'll have to go through the code and see if there is something going on with parsing. Otherwise I don't know 😄 Thanks for all your help!

scottdito avatar Jul 22 '16 14:07 scottdito

I think it relates to the nmcli command - see > https://unix.stackexchange.com/questions/363982/nmcli-command-takes-only-first-string-of-ssid

This works for me > wireless.connect(ssid='"The Name"', password='123')

davidchatting avatar Sep 24 '18 14:09 davidchatting