Home

Selecting access point only once

Updated:
Created:

When using urllib the 'select access point dialog points up all too frequent. But its possible to fix that

With browsing the python s60 forum I was got the impression that

sys.modules['socket'] = __import__('btsocket')

would override the socket module with the btsocket, but it didn't. The 'usual'

apid = socket.select_access_point()
apo = socket.access_point(apid)
socket.set_default_access_point(apo)

did not show any effects when doing urllib.urlopen calls after that - the dialog opens every single time.

The solution seems to be using socket for ip connections, and btsocket for bluetooth stuff.

import socket
import appuifw

aps = [ap['name'] for ap in socket.access_points()]
aps.sort()
apid = appuifw.popup_menu(aps,u'select access point')
socket.set_default_access_point(aps[apid])

import urllib
print 'baach'
urllib.urlopen('http://baach.de/')
print 'google'
urllib.urlopen('http://google.de/')
print 'fini'

The trick is that socket.set_default_access_point takes unicode access point names, in contrast to the btsocket.set_default_access_point, which wants to have an access point object.