I am having a slight issue with an integration I built not interacting with a listener I also built. I think it has something to do with sending codes back from the listener, but I am unable to track this down. Basically the Electron triggers the integration, which sends the POST request out to my Python listener, which does properly receive and parse the data, however in the Integration I receive either a "Socket Hang Up" or "Parse" error, depending on whether or not I try and send response codes back to the Integration after reading the data. I wrote the listener in Python3.
If anyone could put a fresh set of eyes on this that would be awesome. In the Console Logs, it is listed as hook-sent/GPS and then hook-error/GPS/0 (data: Socket Hang Up)
Here is my listener code. (you can see some of the stuff I have been trying in the commented out lines I did not remove. I have removed most of the parsing functions as they are not really relevant to this question.
Thanks Much, Erik....
#!/usr/bin/python3
import socket from http.server import BaseHTTPRequestHandler, HTTPServer import time
hostName = "" hostPort = 8080
class MyServer(BaseHTTPRequestHandler):
# POST is for submitting data. def do_POST(self):
# Handle the actual connection from the client and receive the data inta variable "post_data"
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data print(content_length) headers = str(self.headers) print(headers) post_data = (self.rfile.read(content_length)) # <--- Gets the data itself self.send_response(200) #self.wfile.write("POST request for {}".format(self.path).encode('utf-8')) #time.sleep(0.25) #self.send_response(200) #self.close_connection()
## Handle the data we received from the Electron and parse it for XML files.
print("post_data = {}".format(post_data)) post_data = ' '
myServer = HTTPServer((hostName, hostPort), MyServer) print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
try: myServer.serve_forever() except KeyboardInterrupt: pass
myServer.server_close() print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))