So I'm using MySQL connector and I'm getting an error which is weird because I didn't get any errors with this line before. Please let me know what the issue is.
def update(Sno,Passengers,Distance,Cargo,Aircraft):
myconn=mys.connect(host='localhost',user='root',passwd='adis',database='adis')
if myconn.is_connected():
print('Connection successful')
mycur=myconn.cursor()
query="update AMAS set Passengers={},Distance={},Cargo={},Aircraft={} where Sno={}".format(Passengers,Distance,Cargo,Aircraft,Sno)
mycur.execute(query)
myconn.commit()
print("AMAS Aircraft Database updated")
My error:
Connection successful
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\vinayak\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\vinayak\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 3442, in __call__
self.__callback(self.__value, *args)
File "C:\Users\vinayak\Documents\Programs 12th\Project.py", line 146, in exe
submit()
File "C:\Users\vinayak\Documents\Programs 12th\Project.py", line 127, in submit
update(Sno,Passengers,Distance,Cargo,Aircraft)
File "C:\Users\vinayak\Documents\Programs 12th\Project.py", line 135, in update
mycur.execute(query)
File "C:\Users\vinayak\AppData\Roaming\Python\Python37\site-packages\mysql\connector\cursor.py", line 551, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\vinayak\AppData\Roaming\Python\Python37\site-packages\mysql\connector\connection.py", line 490, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\vinayak\AppData\Roaming\Python\Python37\site-packages\mysql\connector\connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
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 'Distance=,Cargo=,Aircraft= where Sno=' at line 1
Also, I'm new to Stack Overflow so please mention how I can improve asking questions here withput frustrating others.
Related
I'm having a problem with this MySQL Query, how can I fix that?
valori = (message.from_user.id, message.from_user.username)
verifica = "SELECT * FROM utenti WHERE ID = %s, Username = %s"
cursor.execute(verifica, valori)
A sample of variable "valori":
(1062473636, 'Partizionare')
Error:
1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' Username = 'Partizionare'' at line 1
Traceback (most recent call last):
File "/home/lello/.local/lib/python3.7/site-packages/pyrogram/dispatcher.py", line 217, in handler_worker
await handler.callback(self.client, *args)
File "/home/lello/Documents/Telegram/LelloDevBot/pyro.py", line 19, in start
cursor.execute(verifica, valori)
File "/home/lello/.local/lib/python3.7/site-packages/mysql/connector/cursor.py", line 551, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/home/lello/.local/lib/python3.7/site-packages/mysql/connector/connection.py", line 490, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/home/lello/.local/lib/python3.7/site-packages/mysql/connector/connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' Username = 'Partizionare'' at line 1
There's no such thing as , in conditions, you mean AND.
In my code, I am trying to insert data into the 'user_attempts' table of my DB which has two fields: attemptID (auto-incremented) and username. Therefore when I'm passing data in I only have to pass the username as the attemptID is generated by MySQL. This my code:
username='test1'
add_userattempt=mycursor.execute('INSERT INTO user_attempt (username) VALUES %(currentuser)s', {'currentuser' :username})
mydb.commit()
However it returns this error:
Traceback (most recent call last):
File "C:\Users\User\Desktop\project\AA game things\Iteration 1\review.py", line 266, in <module>
reviewPage(screen) # the home screen function is called which essentially starts the whole program.
File "C:\Users\User\Desktop\project\AA game things\Iteration 1\review.py", line 132, in reviewPage
add_userattempt=mycursor.execute('INSERT INTO user_attempt (username) VALUES %(currentuser)s', {'currentuser' :username})
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\cursor.py", line 569, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 590, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 478, in _handle_result
raise errors.get_exception(packet)
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 ''test1'' at line 1
As shown by the error you get, you have a syntax error in your SQL code.
Instead of
mycursor.execute('INSERT INTO user_attempt (username) VALUES %(currentuser)s', {'currentuser' :username})
it should be
mycursor.execute('INSERT INTO user_attempt(username) VALUES(%s)', username)
This webpage here (https://www.mysqltutorial.org/python-mysql-insert/) explains the whole procedure of inserting data into MySQL tables using python pretty well.
Why do you declare your execute statement as a variable?
Hope this helps!
I've caught a problem I can't explain using pygresql for python. This is a simple SELECT query and as far as I can tell the only query that has the problem in the whole script.
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "run_daily_script.py", line 122, in DelegateAPINodes
vm_api_group = Execute(db_conn, fetch_api_group, (cust_id, nodes["node_id"]))
File ".../PreparedQueries.py", line 14, in Execute
result = db.execute(command)
File "/usr/local/lib/python2.7/site-packages/pgdb.py", line 1030, in execute
return self.executemany(operation, [parameters])
File "/usr/local/lib/python2.7/site-packages/pgdb.py", line 1065, in executemany
raise _op_error("Internal error in '%s': %s" % (sql, err))
OperationalError: Internal error in 'SELECT * FROM vm_api_group WHERE cust_id=3 AND node_id=18': insufficient data in "T" message
I ran the query via the console and it works just fine. I monitored psql logs and there were no errors from the database. It seems to be an internal operation with pygresql.
What does "T" mean and how do I fix this?
I am trying to fetch 150 million rows with messages data from data warehouse into my EC2 instance. I have 90GB available space on my disk. When I put my query for running, following is the error I get:
Traceback (most recent call last):
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/result.py", line 964, in fetchall
l = self.process_rows(self._fetchall_impl())
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/result.py", line 915, in _fetchall_impl
return self.cursor.fetchall()
pyodbc.Error: ('08S01', '[08S01] [FreeTDS][SQL Server]Read from the server failed (20004) (SQLFetch)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "en_str.py", line 45, in <module>
INNER JOIN notified.Message m ON c.MessageID = m.MessageID where c.CreateDate>'2016-01-01 00:00:00.0';''',db007_cnxn)
File "/usr/local/anaconda/lib/python3.5/site-packages/pandas/io/sql.py", line 331, in read_sql_query
parse_dates=parse_dates, chunksize=chunksize)
File "/usr/local/anaconda/lib/python3.5/site-packages/pandas/io/sql.py", line 1092, in read_query
data = result.fetchall()
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/result.py", line 970, in fetchall
self.cursor, self.context)
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
exc_info
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 185, in reraise
raise value.with_traceback(tb)
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/result.py", line 964, in fetchall
l = self.process_rows(self._fetchall_impl())
File "/usr/local/anaconda/lib/python3.5/site-packages/sqlalchemy/engine/result.py", line 915, in _fetchall_impl
return self.cursor.fetchall()
sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('08S01', '[08S01] [FreeTDS][SQL Server]Read from the server failed (20004) (SQLFetch)')
My disk space gets full and odbc.log file in tmp folder is taking 90GB space. I have another mounted disk with 100TB space but odbc.log is generated only in tmp folder. What is the solution for this? Any thoughts on how this problem can be solved? Alternatively, how can I change odbc.log file location from 100 GB space disk to the disk with 100 TB space?
Also, instead of giving ec2 instance location, if I give s3 bucket location, will that avoid this odbc.log file?
Any help would be appreciated!
It looks like you may have verbose FreeTDS logging on. Most of the time, the config file is located in /etc/freetds.conf or /etc/freetds/freetds.conf.
You'll want to look for dump file in the FreeTDS log. Also, check odbcinst.ini, as logging can be turned on there.
You'll probably find one of the various logging facilities pointing to /tmp/odbc.log and that'll be your culprit. Good luck!
Can anyone explain the following stack trace, in step by step, please?
I want to find out what the root cause of the error is and where the error originates from.
Traceback (most recent call last):
1. File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensio ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 1 06, in exec_file
exec_code(code, file, global_variables)
2. File "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensio ns\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_util.py", line 8 2, in exec_code
exec(code_obj, global_variables)
3. File "C:\Users\ssr\FindAllCandidatePathsOfTrain.py", line 332, in <module>
main()
4. File "C:\Users\ssr\FindAllCandidatePathsOfTrain.py", line 296, in main
stanoxDetails = checkTheLineHasStanox(lastLineSegment)
5. File "C:\Users\ssr\FindAllCandidatePathsOfTrain.py", line 205, in checkTheLineHasStanox
firstrow= query(queryStr, 'GetOne')
6. File "C:\Users\ssr\FindAllCandidatePathsOfTrain.py", line 45, in query
connection.close()
7. File "C:\Python34\lib\site-packages\pypyodbc.py", line 2658, in close
self.rollback()
8. File "C:\Python34\lib\site-packages\pypyodbc.py", line 2581, in rollback
check_success(self, ret)
9. File "C:\Python34\lib\site-packages\pypyodbc.py", line 988, in check_success
ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)
10. File "C:\Python34\lib\site-packages\pypyodbc.py", line 966, in ctrl_err
raise DatabaseError(state,err_text) pypyodbc.DatabaseError: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Co mmunication
link failure')
Press any key to continue . . .
The traceback shows you the lines of code executed before the error occurred and the error itself, as mentioned. Python isn't the direct cause of the error in this case.
Consider:
10. File "C:\Python34\lib\site-packages\pypyodbc.py", line 966, in ctrl_err
raise DatabaseError(state,err_text) pypyodbc.DatabaseError: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure')
What this shows is that this error in Python is a "pass-through" error. The database driver being called is actually the cause of the error, and Python is simply passing that through Python. Good luck.
A Python Traceback will show you what was being executed before the error occured as well as the line it error-ed on.
In this case, your module raised an error on this line:
File "C:\Python34\lib\site-packages\pypyodbc.py", line 966, in ctrl_err
raise DatabaseError(state,err_text)
And the error text is shown here:
pypyodbc.DatabaseError: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure')