Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie help combining two scripts
#7
I expected that you modify do_GET, but not put it outside
StreamingHandler.
Your StreamingHandler should look like the following:

class StreamingHandler(server.BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/':
            self.send_response(301)
            self.send_header('Location', '/index.html')
            self.end_headers()
        elif self.path == '/index.html':
            content = PAGE.encode('utf-8')
            self.send_response(200)
            self.send_header('Content-Type', 'text/html')
            self.send_header('Content-Length', len(content))
            self.end_headers()
            self.wfile.write(content)
        elif self.path == '/get-temp':
            self.send_response(200)
            self.send_header('Content-Type', 'application/json')
            self.end_headers()
            tf, tc = read_temp()
            self.wfile.write(json.dumps({'temp_c':tf, 'temp_f':tc}))
        elif self.path == '/stream.mjpg':
            self.send_response(200)
            self.send_header('Age', 0)
            self.send_header('Cache-Control', 'no-cache, private')
            self.send_header('Pragma', 'no-cache')
            self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME')
            self.end_headers()
            try:
                while True:
                    with output.condition:
                        output.condition.wait()
                        frame = output.frame
                    self.wfile.write(b'--FRAME\r\n')
                    self.send_header('Content-Type', 'image/jpeg')
                    self.send_header('Content-Length', len(frame))
                    self.end_headers()
                    self.wfile.write(frame)
                    self.wfile.write(b'\r\n')
            except Exception as e:
                logging.warning(
                    'Removed streaming client %s: %s',
                    self.client_address, str(e))
        else:
            self.send_error(404)
            self.end_headers()
Reply


Messages In This Thread
Newbie help combining two scripts - by emuola - Oct-01-2020, 06:36 AM
RE: Newbie help combining two scripts - by scidam - Oct-01-2020, 07:50 AM
RE: Newbie help combining two scripts - by emuola - Oct-01-2020, 10:41 AM
RE: Newbie help combining two scripts - by emuola - Oct-01-2020, 01:45 PM
RE: Newbie help combining two scripts - by emuola - Oct-02-2020, 03:14 PM
RE: Newbie help combining two scripts - by scidam - Oct-02-2020, 10:27 AM
RE: Newbie help combining two scripts - by scidam - Oct-02-2020, 11:39 PM
RE: Newbie help combining two scripts - by emuola - Oct-03-2020, 09:30 AM
RE: Newbie help combining two scripts - by emuola - Oct-03-2020, 02:15 PM
RE: Newbie help combining two scripts - by scidam - Oct-03-2020, 11:45 AM
RE: Newbie help combining two scripts - by emuola - Oct-03-2020, 06:03 PM
RE: Newbie help combining two scripts - by emuola - Oct-04-2020, 07:50 AM
RE: Newbie help combining two scripts - by scidam - Oct-03-2020, 11:40 PM
RE: Newbie help combining two scripts - by scidam - Oct-04-2020, 12:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combining 2 scripts wpothers 5 4,738 Feb-21-2017, 12:38 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020