TypeError: 'top_block_22' object is not callable

Hadad: <p>Hi,</p>
<p>This is AJAX to flask server project.<br>
For more info about this project I have a couple postings about it here, please see <a href="https://python-forum.io/Thread-How-to-control-frequency-sampling-rate-my-dial-tone-through-AJAX-to-flask-server#message" rel="nofollow noopener">link-1</a> <a href="https://python-forum.io/Thread-I-am-having-a-problem-with-my-Slider" rel="nofollow noopener">link-2</a></p>
<p>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.</p>
<p>More details:</p>
<p>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.</p>
<p>Please, I need your help to solve this problem.</p>
<p>error log:<br>
<code>fit</code> <code>-</code> <code>pc@fitpc</code> <code>-</code> <code>fitlet2:~$ python</code> <code>/</code> <code>home</code> <code>/</code> <code>fit</code> <code>-</code> <code>pc</code> <code>/</code> <code>my_flask_app</code> <code>/</code> <code>virtualenv</code> <code>/</code> <code>Slider</code> <code>/</code> <code>top_block_22.py</code></p>
<p><code></code> <code>*</code> <code>Running on http:</code> <code>/</code> <code>/</code> <code>127.0</code> <code>.</code> <code>0.1</code> <code>:</code> <code>5000</code> <code>/</code> <code>(Press CTRL</code> <code>+</code> <code>C to quit)</code></p>
<p><code></code> <code>*</code> <code>Restarting with stat</code></p>
<p><code></code> <code>*</code> <code>Debugger</code> <code>is</code> <code>active!</code></p>
<p><code></code> <code>*</code> <code>Debugger PIN:</code> <code>269</code> <code>-</code> <code>962</code> <code>-</code> <code>008</code></p>
<p><code>127.0</code> <code>.</code> <code>0.1</code> <code>-</code> <code>-</code> <code>[</code> <code>26</code> <code>/</code> <code>Jul</code> <code>/</code> <code>2019</code> <code>11</code> <code>:</code> <code>20</code> <code>:</code> <code>11</code> <code>]</code> <code>"GET / HTTP/1.1"</code> <code>200</code> <code>-</code></p>
<p><code>gr::log :INFO: audio source</code> <code>-</code> <code>Audio sink arch: alsa</code></p>
<p><code>127.0</code> <code>.</code> <code>0.1</code> <code>-</code> <code>-</code> <code>[</code> <code>26</code> <code>/</code> <code>Jul</code> <code>/</code> <code>2019</code> <code>11</code> <code>:</code> <code>20</code> <code>:</code> <code>15</code> <code>]</code> <code>"GET /valueofslider?slide_val=903 HTTP/1.1"</code> <code>500</code> <code>-</code></p>
<p><code>Traceback (most recent call last):</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1997</code> <code>,</code> <code>in</code> <code>__call__</code></p>
<p><code></code> <code>return</code> <code>self</code> <code>.wsgi_app(environ, start_response)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1985</code> <code>,</code> <code>in</code> <code>wsgi_app</code></p>
<p><code></code> <code>response</code> <code>=</code> <code>self</code> <code>.handle_exception(e)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1540</code> <code>,</code> <code>in</code> <code>handle_exception</code></p>
<p><code></code> <code>reraise(exc_type, exc_value, tb)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1982</code> <code>,</code> <code>in</code> <code>wsgi_app</code></p>
<p><code></code> <code>response</code> <code>=</code> <code>self</code> <code>.full_dispatch_request()</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1615</code> <code>,</code> <code>in</code> <code>full_dispatch_request</code></p>
<p><code></code> <code>return</code> <code>self</code> <code>.finalize_request(rv)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1630</code> <code>,</code> <code>in</code> <code>finalize_request</code></p>
<p><code></code> <code>response</code> <code>=</code> <code>self</code> <code>.make_response(rv)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/flask/app.py"</code> <code>, line</code> <code>1740</code> <code>,</code> <code>in</code> <code>make_response</code></p>
<p><code></code> <code>rv</code> <code>=</code> <code>self</code> <code>.response_class.force_type(rv, request.environ)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py"</code> <code>, line</code> <code>921</code> <code>,</code> <code>in</code> <code>force_type</code></p>
<p><code></code> <code>response</code> <code>=</code> <code>BaseResponse(</code> <code>*</code> <code>_run_wsgi_app(response, environ))</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/werkzeug/wrappers.py"</code> <code>, line</code> <code>59</code> <code>,</code> <code>in</code> <code>_run_wsgi_app</code></p>
<p><code></code> <code>return</code> <code>_run_wsgi_app(</code> <code>*</code> <code>args)</code></p>
<p><code></code> <code>File</code> <code>"/usr/lib/python2.7/dist-packages/werkzeug/test.py"</code> <code>, line</code> <code>923</code> <code>,</code> <code>in</code> <code>run_wsgi_app</code></p>
<p><code></code> <code>app_rv</code> <code>=</code> <code>app(environ, start_response)</code></p>
<p><code>TypeError:</code> <code>'top_block_22'</code> <code>object</code> <code>is</code> <code>not</code> <code>callable</code><br>
And here is the Python code:</p>
<pre><code class="lang-auto">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)
</code></pre>
<p>And this is the index.html script:</p>
<pre><code class="lang-auto">&lt;!DOCTYPE html&gt;
   &lt;html&gt;
   &lt;head&gt;
     &lt;meta charset="utf-8"&gt;
     &lt;title&gt;jQuery roundSlider - JS Bin&lt;/title&gt;
     &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"&gt;&lt;/script&gt;
     &lt;link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" /&gt;
     &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"&gt;&lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
     &lt;!-- Only html needed   --&gt;
     &lt;div id="slider"&gt;&lt;/div&gt;
      
     &lt;script&gt;
       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
           });
         }
       });
     &lt;/script&gt;
   &lt;/body&gt;
</code></pre>

Mazhar_Shaikh: <p>Could you replace the line</p>
<pre><code class="lang-auto">gr.top_block.__init__(self, "Top Block 22")
</code></pre>
<p>with the code given below?</p>
<pre><code class="lang-auto">super(self, top_block_22).__init__(self, "Top Block 22")
</code></pre>
<p>Hope this helps.</p>

Hadad: <p>Salam alaykum Mazhar and thanks for your attempt to help. I tried: super(self, top_block_22).<strong>init</strong>(self, “Top Block 22”)  but gave another error: TypeError: super() argument 1 must be type, not top_block_22.</p>
<p>Hadad</p>

Mazhar_Shaikh: <p>Apologies, I comitted an error, Could you try this?</p>
<pre><code class="lang-auto">super(top_block_22, self).__init__(self, "Top Block 22")
</code></pre>

Hadad: <p>This time I got this error:</p>
<p>super(top_block_22, self).<strong>init</strong>(self, “Top Block 22”)<br>
TypeError: <strong>init</strong>() takes at most 2 arguments (3 given)</p>