I am trying to remove a single element from my database using an SDK. I keep getting the following error and I don't know how to fix it:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
return self.func(*args)
File "/Users/jasonsilla/Desktop/Code/Python/Book_GUI_Program/main.py", line 25, in remove_from_list
if booksSDK.delete_book(book):
File "/Users/jasonsilla/Desktop/Code/Python/Book_GUI_Program/booksSDK.py", line 52, in delete_book
c.execute("DELETE FROM books WHERE title=?, pages=?", (book.title, book.pages))
sqlite3.OperationalError: near ",": syntax error
The code for the SDK to remove an element is as follows:
def delete_book(book):
c = cursor()
with c.connection:
c.execute("DELETE FROM books WHERE title=?, pages=?", (book.title, book.pages))
row_count = c.rowcount
c.connection.close()
return row_count
My question is why am I getting this error. I don't understand this, so if anyone can please help me, I believe that either the error in the code is in the:
c.execute("DELETE FROM books WHERE title=?, (<-) pages=?", (book.title, (<- or here) book.pages))
Thank you!!!
The problem is in the 1st arrow:
title=?, (<- here) pages=?
Instead of the comma, you want to put AND. This eliminates the error. Hopefully I helped!!!
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm trying to add data to a table collected on a tkinter GUI. This error keeps coming up:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py", line 489, in cmd_query
raw_as_string=raw_as_string)
_mysql_connector.MySQLInterfaceError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand' at line 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\xande\OneDrive\Desktop\School\YR 14\CCF program\CCF code.py", line 146, in addldrsubmit
mycursor.execute(insertSQL,(LID,str(lunentry),str(lpwentry),str(lfnentry),str(lsnentry),str(lrankentry),str(lemailfullentry),lphoneentry,))
File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\cursor_cext.py", line 266, in execute
raw_as_string=self._raw_as_string)
File "C:\Users\xande\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\connection_cext.py", line 492, in cmd_query
sqlstate=exc.sqlstate)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Rank,Email,Phone) VALUES(5509,'mandy123','password123','Mike','Andy','MJR','mand' at line 1
The code I'm using is:
import mysql.connector
if True:
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="abarclay172",
database="rbaiccf"
)
mycursor=mydb.cursor()
LID = random.randint(1000,9999)
lunentry = lunentrye.get()
lpwentry = lpwentrye.get()
lfnentry = lfnentrye.get()
lsnentry = lsnentrye.get()
lrankentry = addldrranke.get()
lemailentry = lemailentrye.get()
lemailaddressentry = addldremailaddresse.get()
lemailfullentry = lemailentry + lemailaddressentry
lphoneentry = "+44" + lphoneentrye.get()
insertSQL="""INSERT INTO leader(leaderID,Username,Password,Forename,Surname,Rank,Email,Phone) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)"""
mycursor.execute(insertSQL,(LID,str(lunentry),str(lpwentry),str(lfnentry),str(lsnentry),str(lrankentry),str(lemailfullentry),lphoneentry,))
mydb.commit()
From the description you have provided, I guess it is the usage of RANK as a column name. It is a reserved keyword. You could try this solution - using backticks.
But if there is something else going on, you shold provide more info, as stated in comments. Table definition, full SQL, you are trying to execute.
I am new to tkinter and I am trying to connect python with MySQL. When I Try to insert the records via a new window in python I get the following error message
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\sapna\anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\sapna\Desktop\SAMARTH.py", line 141, in dynamic_data_entry
libcur.execute("INSERT INTO tcl VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ,
(id1,name1,auth1,doi1,dor1,reiss,rname,Address,gen1,mil1))
File "C:\Users\sapna\anaconda3\lib\site-packages\mysql\connector\cursor_cext.py", line 248, in
execute
prepared = self._cnx.prepare_for_mysql(params)
File "C:\Users\sapna\anaconda3\lib\site-packages\mysql\connector\connection_cext.py", line 626, in
prepare_for_mysql
result = self._cmysql.convert_to_mysql(*params)
_mysql_connector.MySQLInterfaceError: Python type method cannot be converted
Here is the snip of my insert command.
def dynamic_data_entry():
bname.delete(0,END)
bid.delete(0,END)
author.delete(0,END)
DOI.delete(0,END)
DOR.delete(0,END)
RES.delete(0,END)
RNM.delete(0,END)
AD.delete(0,END)
mail.delete(0,END)
id1=ln.get()
name1=fn.get()
auth1=dn.get()
doi1=an.get()
dor1=gn.get()
rname=kn.get()
Address=pn.get
reiss=mn.get()
gen1=var.get()
mil1=ll.get()
libcur.execute("INSERT INTO tcl VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ,
(id1,name1,auth1,doi1,dor1,reiss,rname,Address,gen1,mil1))
mydb.commit()
messagebox.showinfo("INSERT STATUS","RECORD HAS BEEN ADDED SUCCESSFULLY")
libcur.close()
The datatype that I have used is varchar() in Book_id,DOI,DOR and char() in others for MySQL.
All the dataypes that I have used in Python are as follows
var=StringVar()
fn=StringVar()
yn=StringVar()
ln=StringVar()
dn=StringVar()
an=StringVar()
kn=StringVar()
gn=StringVar()
mn=StringVar()
pn=StringVar()
ll=StringVar()
Thanks in advance
Looks like you missed some parentheses in your assignment to Address. Try Address=pn.get().
The error implies that you're passing a method rather than a value. This is consistent with Address=pn.get, i.e. you're passing the pn.get method rather than the return value of pn.get().
I'm trying to use pandas_profiling to profile a table.
It has around 20 columns most of them are float and almost 3 millions records.
I got the following error :
Traceback (most recent call last): File "V:\Python\prof.py", line
53, in
if name == "main": main() File "V:\Python\prof.py", line 21, in main
df = pd.read_sql(query, sql_conn) File "C:\Users\linus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\sql.py",
line 380, in read_sql
chunksize=chunksize) File "C:\Users\linus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\sql.py",
line 1477, in read_query
data = self._fetchall_as_list(cursor) File "C:\Users\linus\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\sql.py",
line 1486, in _fetchall_as_ list
result = cur.fetchall() MemoryError
I have tried with less record it worked.
Is there a way to bypass this error ? It looks like it is a memory limitation.
Can we do that another way ? Or it is impossible with Python ?
Thanks for you help
If you are in the position to provide information so that we can replicate the error, we can resolve it. I would recommend opening an issue on the github page.
Disclose: I am co-author of this package.
I'm trying to run boto3 to loop through snapshots older than 14 days.
It can find all the snapshots older than 14 days fine, and I've verified that all that works okay. The problem is when it runs through the dictionary trying to delete, it looks like the function isn't correctly evaluating the variable (See below).
It seems to just include it as a string.
The loop runs through the dict using a "for snapshot in ..." if'ing the tags to find the snapshots ready for deletion. Here's the 'if' part:
if snap_start_time < expiry: # check if it's more than a <expiry> old
print "Deleting Snapshot: " + snapshot['SnapshotId']
response = ec2client.delete_snapshot(
SnapshotId=snapshot['SnapshotId']
)
errors here:
Deleting Snapshot: snap-f4f0079d
Traceback (most recent call last):
File "./aws-snap.py", line 27, in <module>
SnapshotId=snapshot['SnapshotId']
File "/usr/lib/python2.6/site-packages/botocore/client.py", line 159, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python2.6/site-packages/botocore/client.py", line 494, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidSnapshot.NotFound) when calling the DeleteSnapshot operation: None
Any clues? \o/
I would doubt that the SnapshotId might not be passing as a string.
Change the SnapshotId to a string format and pass it for deletion.
str(snapshot['SnapshotId'])
As it turns out, referencing straight from the dictionary is a bad idea. It needs to be wrapped in str() and provided with the DryRun=False option too.
I am using a python module called phoenixdb to access phoenix which is SQL wrapper to query over HBase.
Here is my code snippet:-
import phoenixdb
database_url = 'http://localhost:8765/'
conn = phoenixdb.connect(database_url, autocommit=True)
cursor = conn.cursor()
cursor.execute("!table")
print cursor.fetchall()
cursor.close()
The phoenix query to list all the schemes and tables is !table or !tables.
But when I try passing the same in the execute function as shown above, I get the following error:-
Traceback (most recent call last):
File "phoenix_hbase.py", line 7, in <module>
cursor.execute("!table")
File "build/bdist.linux-x86_64/egg/phoenixdb/cursor.py", line 242, in execute
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 345, in prepareAndExecute
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 184, in _apply
File "build/bdist.linux-x86_64/egg/phoenixdb/avatica.py", line 90, in parse_error_page
phoenixdb.errors.ProgrammingError: ("Syntax error. Unexpected char: '!'", 601, '42P00', None)
Funny part is when I try to passing a different query, for example a select query, then script gets executed and produces result just fine.
Query:cursor.execute("select * from CARETESTING.EDR_BIN_SOURCE_3600_EDR_FLOW_SUBS_TOTAL limit 1")
Result:
[[2045,1023,4567]]
Is there any other format for passing !table which is equivalent to show tables in phoenixdb library's execute function which I am missing?
I tried looking up on the internet but unfortunately haven't come across anything helpful so far.
Thanks
!tables is sqlline grammar that can not be parsed by JDBC interface.