I am trying to run the Pybluez server example but I am getting an error that I don't understand. Is there any way to resolve this? I am running Windows 10.
Traceback (most recent call last):
File "C:\Users\cmbro\PycharmProjects\test\server.py", line 10, in <module>
server_sock.bind(("", PORT_ANY))
File "C:\Users\cmbro\PycharmProjects\test\venv\lib\site-packages\bluetooth\msbt.py", line 84, in bind
bt.bind (self._sockfd, addr, port)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Here is the code
from bluetooth import *
server_sock=BluetoothSocket( RFCOMM )
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)
port = server_sock.getsockname()[1]
uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
advertise_service( server_sock, "SampleServer",
service_id = uuid,
service_classes = [ uuid, SERIAL_PORT_CLASS ],
profiles = [ SERIAL_PORT_PROFILE ],
# protocols = [ OBEX_UUID ]
)
print("Waiting for connection on RFCOMM channel %d" % port)
client_sock, client_info = server_sock.accept()
print("Accepted connection from ", client_info)
try:
while True:
data = client_sock.recv(1024)
if len(data) == 0: break
print("received [%s]" % data)
except IOError:
pass
print("disconnected")
client_sock.close()
server_sock.close()
print("all done")
Looks like you're using Python 3.10? There was a breaking change introduced in Python 3.10 (see bpo-40943 and PEP-0353). You need to update pybluez, see: https://github.com/pybluez/pybluez/issues/426.