I want to connect to a Wi-Fi network using Python on OS X (10.11). Based on CWInterface reference I figured out there is a iface.associateToNetwork_password_error_()
method available, however when called it does not connect to the network nor it does cause any exception.
At the same time iface.disassociate()
works correctly and disconnects WiFi.
This is the code I tried:
import objc
objc.loadBundle('CoreWLAN',
bundle_path='/System/Library/Frameworks/CoreWLAN.framework',
module_globals=globals())
iface = CWInterface.interface()
iface.associateToNetwork_password_error_(SSID, PASSWORD, None)
How can I connect to a specified network from Python on OS X and make sure the connection has been established?
I was able to successfully connect to my home network with the following:
import objc
objc.loadBundle('CoreWLAN',
bundle_path = '/System/Library/Frameworks/CoreWLAN.framework',
module_globals = globals())
iface = CWInterface.interface()
networks, error = iface.scanForNetworksWithName_error_('<Name Of Network>', None)
network = networks.anyObject()
success, error = iface.associateToNetwork_password_error_(network, '<Password Of Network>', None)
Two key things that I suspect you were missing:
CWNetwork
as your first parameter.success
and error
in the final call). They could have helped you with tracking down any other issues, perhaps.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With