Python Forum
TypeError: 'top_block_22' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'top_block_22' object is not callable
#1
This is AJAX to flask server project.
For more info about this project I have a couple postings about it here, please see link-1 link-2


When I run the python code in the terminal I get the TypeError: 'top_block_22' object is not callable error. The program starts running without problems, but once I start moving the slider the program will give that error.

More details:

This is AJAX to flask server project. I created a 'Slider' folder inside Flask directory : /home/fit-pc/my_flask_app/virtualenv/Slider. In this folder I have Templates and Static folders. Inside Templates folder I have my index.html file (see below). This index.html file had the script for the roundSlider widget that I am trying to use to control some variable value inside my python code 'top_block_22.py'. My main python code is in the main Slider folder. Static folder is just empty. Please, I need your help to solve this problem.



error log:

    ^Cfit-pc@fitpc-fitlet2:~$ python /home/fit-pc/my_flask_app/virtualenv/Slider/top_block_22.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 - - [26/Jul/2019 11:20:11] "GET / HTTP/1.1" 200 -
    gr::log :INFO: audio source - Audio sink arch: alsa
    127.0.0.1 - - [26/Jul/2019 11:20:15] "GET /valueofslider?slide_val=903 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 1740, in make_response
        rv = self.response_class.force_type(rv, request.environ)
      File "/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 921, in force_type
        response = BaseResponse(*_run_wsgi_app(response, environ))
      File "/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 59, in _run_wsgi_app
        return _run_wsgi_app(*args)
      File "/usr/lib/python2.7/dist-packages/werkzeug/test.py", line 923, in run_wsgi_app
        app_rv = app(environ, start_response)
    TypeError: 'top_block_22' object is not callable
Python code:

 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
    
    
    class top_block_22(gr.top_block):
    
    
        def __init__(self, slide_val): 
        	self.slide_val = slide_val
    
            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 = Flask(__name__)
    @app.route('/')
    def hex_color():
            return render_template("index.html")
    @app.route('/valueofslider')
    def slide():
        slide_val = request.args.get('slide_val')
        return top_block_22(slide_val)     
    
    
    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()
      
        samp_rate = int(slide_val) + 100
        print(samp_rate)
        return(slide_val) # Still need to return or get TypeError 
     
    if __name__ == '__main__':
        app.run(debug=True)
index.html script:

 <!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
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 268 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 444 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 678 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 917 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,260 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 775 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,044 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 3,835 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  'SSHClient' object is not callable 3lnyn0 1 1,125 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,368 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

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