Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误:";ValueError:以10为基数的int()的文本无效:'';从Tk条目小部件向sql数据库传递值时_Python_Sql_Pyodbc - Fatal编程技术网

Python 错误:";ValueError:以10为基数的int()的文本无效:'';从Tk条目小部件向sql数据库传递值时

Python 错误:";ValueError:以10为基数的int()的文本无效:'';从Tk条目小部件向sql数据库传递值时,python,sql,pyodbc,Python,Sql,Pyodbc,我正在尝试从TkinterGUI向sql数据库中插入值。但是,我得到了以下错误ValueError:以10为基数的int()的文本无效:“” 代码如下: con = cx_Oracle.connect("system/abc123") print("connected") cursor = con.cursor() sql = "insert into student values('%d','%s','%d')" rno = int(entRno.get

我正在尝试从TkinterGUI向sql数据库中插入值。但是,我得到了以下错误ValueError:以10为基数的int()的文本无效:“” 代码如下:

    con = cx_Oracle.connect("system/abc123")
    print("connected")
    cursor = con.cursor()
    sql = "insert into student values('%d','%s','%d')"
    rno = int(entRno.get())
    name = entName.get()
    marks = int(entMarks.get())
    args = (rno,name,marks)
    cursor.execute(sql % args)
    con.commit()
    msg = str(cursor.rowcount) + " records inserted"
    messagebox.showinfo("Success",msg)
以下是回溯:

Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in__call__
return self.func(*args)
File "C:\Users\Admin\Desktop\Tkinter Project\sam.py", line 108, in f5
rno = int(entRno.get())
ValueError: invalid literal for int() with base 10: ''

我应该怎么做才能解决这个问题?

我想您可能需要尝试在try/except块中传入int值。这个链接看起来很有资源: 像这样

try:
   rno = int(rno)
   break
except ValueError:
   raise (ValueError, print(some debug message or warning issue)

什么是entRno?@rogerdpack entRno是用于接受值的条目小部件变量,就像entRno说它有一个空值一样?(空字符串)错误是告诉您正在尝试将空字符串转换为int,而python无法做到这一点。因为您没有给我们提供一个int,所以我们无法说出。很明显,在代码运行时,entry小部件或其变量为空。