Python Forum
TypeError: int() argument must be a string or a number, not 'NoneType'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: int() argument must be a string or a number, not 'NoneType'
#1
Hi,

I'm getting this error when I run the following code. Any help to solve it would be highly appreciated.

app.py code:

from flask import Flask, render_template, jsonify,request,redirect,url_for
from random import randint
from top_block_22 import top_block_22
 
app = Flask(__name__)
@app.route('/')
def slide_func():
    return render_template("index.html")
 
@app.route('/valueofslider')
def slide():
    slide_val = request.form.get('slide_val')
    return main(slide_val)   
 
def main(slide_val):
    '''Code outside of route'''
    tb = top_block_22()
    tb.start()
    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)
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: 100000,
       change: function () {

        var obj1 = $("#slider").data("roundSlider");
        val = obj1.getValue();
        value: 10
        $.getJSON('/valueofslider', {
          slide_val: val
        });
      }
    });
  </script>
</body>
dial_tone_22.py 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
from app import *

   



class top_block_22(gr.top_block):

    def __init__(self):

    #def __init__(self, slide_val):

        #self.slide_val = slide_val


        #gr.top_block.__init__(self, "Top Block 22")
        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))

   

def main(top_block_cls=top_block_22, options=None):
   
 
    tb = top_block_22()
    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__':
        main()
[Image: wTYv04.png]
Reply
#2
The problem with your code is that its not real code, its a picture of code, pictures of code cant be run.

If t was real code the value the variable slide_val is pointing contains None , int cannot turn None into a number.
Reply
#3
(Jul-30-2019, 06:55 PM)Yoriz Wrote: its not real code, its a picture of code

Sorry about that Yoriz. I just updated my post.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: 'NoneType' object is not subscriptable syafiq14 2 1,855 Aug-26-2021, 06:18 AM
Last Post: alexaminar
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 550 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  TypeError: __init__() got an unexpected keyword argument 'value' Anldra12 7 5,443 May-11-2021, 06:35 PM
Last Post: deanhystad
  TypeError: int() argument must be a string, a bytes-like object or a number, not 'Non Anldra12 2 1,738 May-02-2021, 03:45 PM
Last Post: Anldra12
  [solved] Variable number of dictionnaries as argument in def() paul18fr 11 2,045 Apr-20-2021, 11:15 AM
Last Post: paul18fr
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 2,495 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  cursor.execute: How to insert dynamic number in a string? stoeberhai 2 1,116 Mar-18-2021, 12:55 PM
Last Post: stoeberhai
  Regular expression: cannot find 1st number in a string Pavel_47 2 924 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 1,788 Jan-06-2021, 04:25 PM
Last Post: Insen
  TypeError: string indices must be integers hendern 2 1,258 Oct-02-2020, 10:16 PM
Last Post: hendern

Forum Jump:

User Panel Messages

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