i want some help with my program. My objective is to stream with IP Camera in webserver flask with bootstrap, i figure out how i do that and also i made the web interface like input box and buttons... but the problem is when i wrote the ip address of IP camera in the input box i got this error:
ValueError: View function did not return a response
Looks like it doesn't return the ip address as input from html file to my function in python file.
Here want i have try so far...
html file:
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Live Streaming</h1>
</div>
<ul class="list-group">
<li class="list-group-item">Stream with IP Camera: <span><a href="#" class="btn btn-sm btn-primary" id="IPcambtn">Start</a></span>
</li>
</ul>
<div id="IPcam" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="IPcamlbl" aria-hidden="true">
<div class="vertical-alignment-helper">
<div class="modal-dialog modal-sm vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="IPcambl">Enter camera's IP address:</h4>
</div>
<div class="modal-body">
<form action="" role="form" id="IPcam" method="post">
<input type="hidden" name="formType" value="IPcam">
<div class="form-group">
<label for="basic-url">IP Address:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon3">rtsp://</span>
</div>
<input name="IPaddress" type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" style="width: 275px;>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs- col-xs-offset- text-center">
<!-- Do NOT use name="submit" or id="submit" for the Submit button -->
<button type="submit" class="btn btn-danger" tabindex="3">Confirm</button>
<div class="panel-body">
<img id="pic" src="" class="img-responsive img-rounded"></img>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
python file:
class Stream(flask.views.MethodView):
@login_required
def get(self):
return flask.render_template('stream.html')
def post(self):
formType = flask.request.form.get('formType')
IPcamPass = ""
if formType == "IPcam":
required = ['IPaddress']
for r in required:
IPcamPass += flask.request.form.get(r)
print ("Connecting with IP Camera...")
database().writeLogs("IP Camera connection established")
flask.flash("You are now connected with IP Camera")
IPstream()
#Functions for IP Camera streaming.
@app.route('/IPstream')
def IPstream():
return Response(IPcam(),mimetype='multipart/x-mixed-replace; boundary=frame')
return ""
def IPcam():
camera = cv2.VideoCapture(IPaddress)
while True:
success, frame = camera.read() # read the camera frame
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
Error:
Traceback (most recent call last)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/middleware/proxy_fix.py", line 228, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1615, in full_dispatch_request
return self.finalize_request(rv)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1630, in finalize_request
response = self.make_response(rv)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1725, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
Aucun commentaire:
Enregistrer un commentaire