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....

#!/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))

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.

Thanks,

Erik

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.

add:

self.end_headers()

after you deal with the headers. whoops. Ouch.

Erik