Python Forum
[SOLVED ]ValueError: View function did not return a response
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED ]ValueError: View function did not return a response
#1
I am getting the below error when I run my code. The story is, I am trying to control the frequency sampling rate of my dial_tone python code through a AJAX for to flask server.

Update Update Update:
I was told that The request GET /valueofslider?slide_val=277 did not include a samp_rate parameter, therefore request.args.get('samp_rate') returns None. Views can't return None. That hint helped me fixed the error. The only problem left is sliding/changing values doesn't run the 'tone' sound.

Error log:

^Cfit-pc@fitpc-fitlet2:~$ python /home/fit-pc/my_flask_app/virtualenv/Slider/top_bloc22.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 269-962-008
127.0.0.1 - - [24/Jul/2019 10:24:26] "GET / HTTP/1.1" 200 -
None
127.0.0.1 - - [24/Jul/2019 10:24:30] "GET /valueofslider?slide_val=277 HTTP/1.1" 500 -
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/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
Once I cancel the process on the Terminal (ctrl + c) my program will start working (which is a simple dial tone)!

This is the Python code:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block 22
# Generated: Tue Jul 23 15:54:16 2019
##################################################
 
 
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
from flask import Flask, render_template, jsonify, request, redirect, url_for
from random import randint
app = Flask(__name__)
 
 
class top_block_22(gr.top_block):
 
    def __init__(self):
        gr.top_block.__init__(self, "Top Block 22")
 
        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
 
        ##################################################
        # Blocks
        ##################################################
        self.blocks_add_xx = blocks.add_vff(1)
        self.audio_sink = audio.sink(32000, '', True)
        self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, 0.4, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, 0.4, 0)
        self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)
 
        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
        self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
 
 
    @app.route('/')
    def hex_color():
            return render_template("index.html")
          
    @app.route('/valueofslider')
    def slide():
            samp_rate = request.args.get('samp_rate')
            print(samp_rate)
            return samp_rate 
 
def main(top_block_cls=top_block_22, options=None):
 
 
 
    tb = top_block_cls()
    tb.start()
    try:
        raw_input('Press Enter to quit: ')
    except EOFError:
        pass
    tb.stop()
    tb.wait()
 
if __name__ == '__main__':
    app.run(debug=True)
 
if __name__ == '__main__':
    main()
The html code is:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>jQuery roundSlider - JS Bin</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>
</head>
<body>
  <!-- Only html needed   -->
  <div id="slider"></div>
    
  <script>
    var val;
    $("#slider").roundSlider({
      radius: 215,
        min: 0,
        max: 40000,
 
      change: function () {
        var obj1 = $("#slider").data("roundSlider");
        val = obj1.getValue();
        value: 1
        $.getJSON('/valueofslider', {
          slide_val: val
        });
      }
    });
  </script>
</body>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  nested function return MHGhonaim 2 562 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  [SOLVED] Looking for documentation on Reportlab's canvas.transform() function NeilUK 1 554 Aug-23-2023, 01:21 PM
Last Post: NeilUK
  Receiving this error in my "response" and causes script to return wrong status cubangt 18 1,912 Aug-13-2023, 12:16 AM
Last Post: cubangt
  return next item each time a function is executed User3000 19 2,175 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,191 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  function return boolean based on GPIO pin reading caslor 2 1,131 Feb-04-2023, 12:30 PM
Last Post: caslor
  [Solved] unkown (to me) function def parm "name1:name2" syntax. MvGulik 5 988 Nov-11-2022, 11:21 AM
Last Post: MvGulik
  [Solved]Return values from npyscreen Extra 2 1,093 Oct-09-2022, 07:19 PM
Last Post: Extra
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  How to invoke a function with return statement in list comprehension? maiya 4 2,753 Jul-17-2021, 04:30 PM
Last Post: maiya

Forum Jump:

User Panel Messages

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