Skip to content

Make fauxmo.py python3 compatible. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ any code you want.

### Instructions

All of the code to make it work is contained in the single file, `fauxmo.py`. It
requires Python 2.7 and standard libraries. The example handler class that
All of the code to make it work is contained in the single file, `fauxmo.py`, which is python 2, and 3 compatible. The example handler class that
reacts to on and off commands uses the [python-requests](http://docs.python-requests.org/en/latest/)
library, but could be replaced with code that does the same thing in many
different ways.
Expand Down
12 changes: 6 additions & 6 deletions fauxmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
def dbg(msg):
global DEBUG
if DEBUG:
print msg
print(msg)
sys.stdout.flush()


Expand Down Expand Up @@ -300,17 +300,17 @@ def init_socket(self):

try:
self.ssock.bind(('',self.port))
except Exception, e:
except Exception as e:
dbg("WARNING: Failed to bind %s:%d: %s" , (self.ip,self.port,e))
ok = False

try:
self.ssock.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,self.mreq)
except Exception, e:
except Exception as e:
dbg('WARNING: Failed to join multicast group:',e)
ok = False

except Exception, e:
except Exception as e:
dbg("Failed to initialize UPnP sockets:",e)
return False
if ok:
Expand Down Expand Up @@ -343,7 +343,7 @@ def recvfrom(self,size):
return self.ssock.recvfrom(size)
else:
return False, False
except Exception, e:
except Exception as e:
dbg(e)
return False, False

Expand Down Expand Up @@ -417,7 +417,7 @@ def off(self):
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
except Exception as e:
dbg(e)
break