I am working on a project on a Raspberry Pi. I am trying to autorun a Python script automatically when the Raspberry Pi is powered up. However, this Python script generates an HTTPS link to access a flask server. I am facing a problem as when the raspberry pi is turned on it does not run the python script. For the autorun code, I have tried the crontab, rc.local, and the autostart folder but in vain. After some debugging, I have figured out that the problem causing the python script not to autorun is the ssl_context present in the main of the code.
When I tried to run the code from thonny it ran fine. But when booting the pi it does not run. I have provided the code below. I would really appreciate any kind of help. Thank you in advance.
from flask import Flask, render_template, Response, request from flask import Flask, jsonify, request from camera_a import VideoCamera import time import threading import os #import ssl pi_camera = VideoCamera(flip=True) # flip pi camera if upside down. # App Globals (do not edit) app = Flask(__name__) @app.route("/") def index(): return render_template('index.html') #you can customze index.html here print("starting") def gen(camera): #get camera frame while True: frame = camera.get_frame() yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') @app.route('/video_feed') def video_feed(): return Response(gen(pi_camera), mimetype='multipart/x-mixed-replace; boundary=frame') if __name__ == '__main__': app.run(host='0.0.0.0', debug=False, ssl_context=('cert.pem','key.pem'))
Where cert.pem and the key.pem are the server cerificate and the private key respectively.