khashayarbayati
Posts: 3
Joined: Wed Jun 24, 2015 10:57 am

Bluetooth Problem

Wed Jun 24, 2015 11:07 am

I'm trying to do some Bluetooth programming with a Raspberry PI, but I have a problem. I want to use 'get_available_port' method, when I run the .py code, an AttributeError accrues, that it says " 'module' object has no attribute 'get_available_port ". I would be very thankful if someone could help me!

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Bluetooth Problem

Wed Jun 24, 2015 1:03 pm

Post your code and full error message please.

That error can often arise when you give your script the same name as a python module that you're trying to import. i.e. if your script has the line:

Code: Select all

import bluetooth
don't call your script bluetooth.py
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

khashayarbayati
Posts: 3
Joined: Wed Jun 24, 2015 10:57 am

Re: Bluetooth Problem

Wed Jun 24, 2015 1:20 pm

here is my code:
import bluetooth

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = bluetooth.get_available_port( bluetooth.RFCOMM )
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )

client_sock,address = server_sock.accept()
print "Accepted connection from ",address

data = client_sock.recv(1024)
print "received [%s]" % data

client_sock.close()
server_sock.close()

#and this is my error
'module' object has no attribute 'get_available_port'

thank u for replying :)

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Bluetooth Problem

Wed Jun 24, 2015 1:34 pm

Please use code tags when pasting python code.

Also paste the full error message, it usually gives you a line number, file name details as well.

Looking at the PyBluez documentation (I assume this is the module you're using) it says this:
get_available_port(protocol)

deprecated. bind to port zero instead.
So maybe try commenting out your line and just setting port to zero.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Python”