Socket Hang Up - Integration Questions

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…


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
                headers = str(self.headers)
                post_data = ( # <--- Gets the data itself
                #self.wfile.write("POST request for {}".format(self.path).encode('utf-8'))
##      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))
except KeyboardInterrupt:
print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))

Let me ping someone that might be able to help, @blave are you able to assist?

Thanks You for the assist.

One other thing I guess I forgot to include, because i was getting burned out.

When I use the self.wfile.write with or without self.send_response() but definitely without self.close_connection, instead of “Socket Hang Up” errors, I was receiving “Parse Error” instead. I thought this may be due to the POST sending JSON and maybe wanting JSON in return, but without a more detailed error, I just am not sure.

I am just not familiar enough with this Python library nor how this client/listener relationship is working to fix it, except through continuing brute force efforts of modifying code and testing.



OK, just wanted to add the solution in case anyone gets into this same bind. It was quite simple and I felt dumb once someone from Particle emailed me back the answer.



after you deal with the headers. whoops. Ouch.