K
K
Kt0T02021-04-20 19:14:33
Python
Kt0T0, 2021-04-20 19:14:33

Misunderstood error?

I can't figure out what's the problem

Code with an error
def send_messange():
    delete_query = "DELETE FROM music LIMIT 1"
    cur.execute(delete_query)
    con.commit()

schedule.every().day.at('19:09').do(send_messange)

while True: # этот цикл отсчитывает время. Он обязателен.
    schedule.run_pending()
    time.sleep(1)


Mistakes

Traceback (most recent call last):
File "C:\Users\danil\Desktop\MusicBot\main.py", line 148, in
schedule.run_pending()
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\schedule\__init__.py", line 563, in run_pending
default_scheduler.run_pending()
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\schedule\__init__.py", line 94, in run_pending
self._run_job(job)
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\schedule\__init__.py", line 147, in _run_job
ret = job.run()
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\schedule\__init__.py", line 466, in run
ret = self.job_func()
File "C:\Users\danil\Desktop\MusicBot\main.py", line 142, in send_messange
cur.execute(delete_query)
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\cursors.py", line 148, in execute
result = self._query(query)
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\cursors.py", line 310, in _query
conn.query(q)
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 547, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "C:\Users\danil\AppData\Local\Programs\Python\Python38\lib\site-packages\pymysql\connections.py", line 793, in _execute_command
raise err.InterfaceError(0, "")
pymysql.err.InterfaceError: (0, '')
[Finished in 25.4s]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
galaxy, 2021-04-20
@Kt0T0

def _execute_command(self, command, sql):
        """
        :raise InterfaceError: If the connection is closed.
        :raise ValueError: If no username was specified.
        """
        if not self._sock:
            raise err.InterfaceError(0, "")

https://github.com/PyMySQL/PyMySQL/blob/master/pym...
Someone is closing the connection (or not opening it).

Y
Yupiter7575, 2021-04-20
@yupiter7575

I think there must be something between DELETE and FROM...

V
Vadim Shatalov, 2021-04-20
@netpastor

Are you sure you wrote the request correctly?
LIMIT is usually used to limit the sample size in a SELECT
Example - display one last record:
SELECT * FROM music LIMIT 1
WHERE in DELETE is used to set a condition on which data will be deleted
For example - delete all records for id 1:
DELETE FROM music WHERE id= one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question