python\bluetooth / wsgi / apache 2.2

Barry Dick at
Thu Dec 13 21:04:39 CET 2012

I'm wanting to read from my bluetooth device (it just sends data/header with a checksum at the end, in a continuous mode "a biofeedback device") and I'm getting a weird error in my logs not allowing me to use multiple sockets. I guess with wsgi, I'm creating a link/module between the two apis (apache / python), and then lets apache manage the socket / port communication on the application layer. How ever, I'm not able to connect to my device. Is there something simple I'm missing? The test code is the following


# Written by Yevgeniy Medynskiy (eugenem at
# Date modified: December 2006
# No copyright. No warranty. Distributed as-is.

import time
import bluetooth
import sys

class MyWriter:

    def __init__(self, stdout, filename):
        #self.stdout = stdout
        self.logfile = file(filename, 'a')

    def write(self, text):

    def close(self):

writer = MyWriter(sys.stdout, 'logging.txt')
sys.stdout = writer

## Change to your device's Bluetooth address
device = "10:00:E8:AC:4D:D0"

port = 1

## Read command and request for acknowledgement.

socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)

#print "Attempting to connect to " + device + ":" + str(port) + "...",
socket.connect((device, port))
#print "done."

#print "Receiving data..."

data = ""
	while True:
			data = socket.recv(255)
		except bluetooth.BluetoothError, b:
			print "Bluetooth Error: ", b

		if len(data) > 0: print data

except KeyboardInterrupt:
	#print "Closing socket...",
	#print "done."

[Wed Dec 12 17:00:31 2012] [error] [client] mod_wsgi (pid=2780): Target WSGI script 'C:/Project/' cannot be loaded as Python module.
[Wed Dec 12 17:00:31 2012] [error] [client] mod_wsgi (pid=2780): Exception occurred processing WSGI script 'C:/Project/'.
[Wed Dec 12 17:00:31 2012] [error] [client] Traceback (most recent call last):
[Wed Dec 12 17:00:31 2012] [error] [client]   File "C:/Project/", line 45, in <module>
[Wed Dec 12 17:00:31 2012] [error] [client]     socket.connect((device, port))
[Wed Dec 12 17:00:31 2012] [error] [client]   File "C:\\Python26\\lib\\site-packages\\bluetooth\\", line 53, in connect
[Wed Dec 12 17:00:31 2012] [error] [client]     bt.connect (self._sockfd, addr, port)
[Wed Dec 12 17:00:31 2012] [error] [client] IOError: Only one usage of each socket address (protocol/network address/port) is normally permitted.\r
[Wed Dec 12 17:00:31 2012] [error] [client] 

I realize that in order for me to feed information back to apache and then onto my client, is I need to def application().... but I wanted to make sure it was just that, and not something that I don't know about using sockets.

More information about the Python-list mailing list