Issue
First the context : I Want to send some data with a Bluetooth connection. And to do that I want to use Python 3.6 because it's with this programming language that I coded the rest of the algorithm. I use it on a Raspbian Jessie lite for raspberry pi based on Debian Jessie. The problem is that when I use this code :
import socket
hostMACAddress = 'xx:xx:xx:xx:xx:xx' # The MAC address of a Bluetooth adapter on the server
port = 3
backlog = 1
size = 1024
s=socket.socket(socket.AF_BLUETOOTH,socket.SOCK_STREAM,socket.BTPROTO_RFCOMM)
s.bind((hostMACAddress,port))
s.listen(backlog)
try:
client, address = s.accept()
while 1:
data = client.recv(size)
if data:
print("data")
client.send(data)
except:
print("Closing socket")
client.close()
s.close()
This error look like :
Traceback (most recent call last):
File "TestSocket.py", line 5, in <module>
s =socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
AttributeError: module 'socket' has no attribute 'AF_BLUETOOTH'
I used it from a site which indicate that it's functionnal for Python 3.3 and above. It's complicate because without this attribute I don't know how use socket module to establish bluetooth connection and send data correctly. I am not an expert in Python so any help is welcome or with Debian distribution. Thinx for you time and sorry for any syntax error or misspellings english is not my mother tongue.
Solution
Raspbian comes with two Python versions installed, 2.7 & 3.4.
Python 2.7 is the default so typing python script.py
at the command prompt will run the script against Python 2.7
If you use python3 script.py
you should find your script works
Also please note that the latest Python version available for Raspbian Jessie is 3.4
Answered By - Zander Brown