rockymeza / wifi

[unmaintained] WiFi tools for linux
http://pypi.python.org/pypi/wifi
BSD 2-Clause "Simplified" License
305 stars 151 forks source link

Scheme.for_cell fails with TypeError if optional argument is not passed #56

Open leokoppel opened 9 years ago

leokoppel commented 9 years ago

(This was reported on StackOverflow here).

An uncaught TypeError is raised when Scheme.for_cell is called for an encrypted cell, without the optional passkey argument.

When no passkey is supplied, for_cell calls configuration with passkey=None , which, if the encryption happens to be 'wpa', fails on len(passkey) in scheme.py:23:

TypeError: object of type 'NoneType' has no len()
rockymeza commented 9 years ago

Hi @leokoppel,

This is not a very friendly error message now is it.

I think that Scheme.for_cell could check if the cell is encrypted and then throw a TypeError about the missing passkey. Do you think that is appropriate? It would still result in an error, but at least we could control the error message.

leokoppel commented 9 years ago

Not sure about TypeError as the arguments given do match the function definition; they only go awry of the business logic. A custom exception like InterfaceError seems more appropriate.

I would have submitted a pull request to do this but the intended behaviour was not clear. For example, if the encryption type is 'wep', it would just return with 'wireless-key' : None and presumably fail upon trying to connect, but not before. So it's a design decision, up to you.