git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pymysql.err.InterfaceError after some hours of usage


MySQL connection can be closed automatically by various reasons.
For example, `wait_timeout` is the most common but not only reason for
closing the connection.

You should connect and close MySQL connection for each HTTP request.

Or you can use more smart connection pool (e.g. Engine in SQLAlchemy).
It provides `pool_recycle` and `pool_pre_ping` options.

https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle
https://docs.sqlalchemy.org/en/13/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping

On Wed, Oct 2, 2019 at 2:16 PM ????? ?????? <vergos.nikolas at gmail.com> wrote:
>
> Hello, i use 'module pymysql' for connectivity in my wsgi scripts. For some reason after some hours of i.e. 'http://superhost.gr/files' i get the following error when the script tries to run:
> Do you know why this is happening?!
>
>
> Error: 500 Internal Server Error
> Sorry, the requested URL 'http://superhost.gr/files/' caused an error:
>
> Internal Server Error
> Exception:
> InterfaceError("(0, '')",)
> Traceback:
> Traceback (most recent call last):
>   File "/usr/lib/python3.6/site-packages/bottle.py", line 862, in _handle
>     return route.call(**args)
>   File "/usr/lib/python3.6/site-packages/bottle.py", line 1740, in wrapper
>     rv = callback(*a, **ka)
>   File "/home/nikos/wsgi/files.py", line 143, in displayall
>     convert()
>   File "/home/nikos/wsgi/files.py", line 93, in convert
>     cur.execute('''SELECT file FROM files''')
>   File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
>     result = self._query(query)
>   File "/usr/lib64/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
>     conn.query(q)
>   File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 516, in query
>     self._execute_command(COMMAND.COM_QUERY, sql)
>   File "/usr/lib64/python3.6/site-packages/pymysql/connections.py", line 750, in _execute_command
>     raise err.InterfaceError("(0, '')")
> pymysql.err.InterfaceError: (0, '')
>
>
>
> I only use this opening statement in the beginning of my scripts.
>
> conn = pymysql.connect( host='localhost', user='user', password='pass', db='counters' )
> cur = conn.cursor()
>
> Then i execute insert and update sql statements but i never close the connection. I presume python closes the connection when the script ends. Doesn't it?
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Inada Naoki  <songofacandy at gmail.com>