python error 32512 Topic is solved

Python and python framework

Moderator: leecollings

Post Reply
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

python error 32512

Post by markjgabb »

hi guys


anyone able to shed some light on this python code for me?
i can run the code with sudo or without and it works
but in domoticz i get a error
2017-07-12 06:50:39.716 Executing script: /home/pi/domoticz/scripts/python/wemo_off.py
2017-07-12 06:50:39.726 Error: Error executing script command (/home/pi/domoticz/scripts/python/wemo_off.py). returned: 32512
i have chmod the file to 777
is there something inside domoticz ive missed for permissions?
as i said it works perfectly in console with or without root so im unsure whats now blocking it

Code: Select all

#!/usr/bin/python

import re
import urllib2

# Configuration:
# Enter the local IP address of your WeMo in the parentheses of the ip variable below. 
# You may have to check your router to see what local IP is assigned to the WeMo.
# It is recommended that you assign a static local IP to the WeMo to ensure the WeMo is always at that address.
# Uncomment one of the triggers at the end of this script.

ip = '10.0.0.3'


class wemo:
	OFF_STATE = '0'
	ON_STATES = ['1', '8']
	ip = None
	ports = [49153, 49152, 49154, 49151, 49155]

	def __init__(self, switch_ip):
		self.ip = switch_ip      
   
	def toggle(self):
		status = self.status()
		if status in self.ON_STATES:
			result = self.off()
			result = 'WeMo is now off.'
		elif status == self.OFF_STATE:
			result = self.on()
			result = 'WeMo is now on.'
		else:
			raise Exception("UnexpectedStatusResponse")
		return result    

	def on(self):
		return self._send('Set', 'BinaryState', 1)

	def off(self):
		return self._send('Set', 'BinaryState', 0)

	def status(self):
		return self._send('Get', 'BinaryState')

	def name(self):
		return self._send('Get', 'FriendlyName')

	def signal(self):
		return self._send('Get', 'SignalStrength')
  
	def _get_header_xml(self, method, obj):
		method = method + obj
		return '"urn:Belkin:service:basicevent:1#%s"' % method
   
	def _get_body_xml(self, method, obj, value=0):
		method = method + obj
		return '<u:%s xmlns:u="urn:Belkin:service:basicevent:1"><%s>%s</%s></u:%s>' % (method, obj, value, obj, method)
	
	def _send(self, method, obj, value=None):
		body_xml = self._get_body_xml(method, obj, value)
		header_xml = self._get_header_xml(method, obj)
		for port in self.ports:
			result = self._try_send(self.ip, port, body_xml, header_xml, obj) 
			if result is not None:
				self.ports = [port]
			return result
		raise Exception("TimeoutOnAllPorts")

	def _try_send(self, ip, port, body, header, data):
		try:
			request = urllib2.Request('http://%s:%s/upnp/control/basicevent1' % (ip, port))
			request.add_header('Content-type', 'text/xml; charset="utf-8"')
			request.add_header('SOAPACTION', header)
			request_body = '<?xml version="1.0" encoding="utf-8"?>'
			request_body += '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
			request_body += '<s:Body>%s</s:Body></s:Envelope>' % body
			request.add_data(request_body)
			result = urllib2.urlopen(request, timeout=3)
			return self._extract(result.read(), data)
		except Exception as e:
			print str(e)
			return None

	def _extract(self, response, name):
		exp = '<%s>(.*?)<\/%s>' % (name, name)
		g = re.search(exp, response)
		if g:
			return g.group(1)
		return response

def output(message):
	print message

switch = wemo(ip)

# Configuration:
# Uncomment only one of the lines below to make the script work.


#output(switch.on())
output(switch.off())
#output(switch.toggle())
#output(switch.status())
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: python error 32512

Post by markjgabb »

so googling has taught me that 32512 means command cant be found....
which makes even less sense, as it works!!!!
i can run from the console
even SU into root then running it works as well....so im completely bamboozled

the only thing i can think of otherwise is the fact that it returns 1 or 0 if its on of off command.....and i think in all my reading i found out something about this.....

any advice anyone?
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: python error 32512

Post by markjgabb »

Resolved....


to anyone else who is suffering similar issues with no idea of whats happening...

try opening the file using "vi"

check for your line endings and make sure they are in unix format
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
kevster
Posts: 26
Joined: Tuesday 06 December 2016 23:14
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK
Contact:

Re: python error 32512

Post by kevster »

Had the same......

Opened it in Notepad++ and converted to Unix (just LF, rather than CR LF) and the Python script ran.

Go figure !
joran
Posts: 7
Joined: Friday 22 June 2018 0:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Contact:

Re: python error 32512

Post by joran »

Thank you so much, I had the same issue and solved it using Notepad++
TJLuijt
Posts: 8
Joined: Monday 09 July 2018 16:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: The Netherlands, Almere
Contact:

Re: python error 32512

Post by TJLuijt »

kevster wrote: Wednesday 11 April 2018 0:06 Had the same......

Opened it in Notepad++ and converted to Unix (just LF, rather than CR LF) and the Python script ran.

Go figure !
yeah...
Opened script in notepad ++ --> "edit - EOL Conversion - Unix (LF)" --> saved it.

After putting it back in scripts and tried again it ran straight away.
Raspberry pi
Zigbee2MQTT
Z-Wave usb
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest