Since some days I am having this error from time to time in my Flask Website
[Sat Sep 14 00:04:31.016107 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/__init__.py", line 1612, in showArticleTitlePage
[Sat Sep 14 00:04:31.016119 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] language = session['locale'])
[Sat Sep 14 00:04:31.016130 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/cardsrealm/SQL.py", line 1376, in get_articles_before
[Sat Sep 14 00:04:31.016146 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] cursor.execute(query, t)
[Sat Sep 14 00:04:31.016176 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
[Sat Sep 14 00:04:31.016188 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] result = self._query(query)
[Sat Sep 14 00:04:31.016198 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
[Sat Sep 14 00:04:31.016209 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] conn.query(q)
[Sat Sep 14 00:04:31.016219 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query
[Sat Sep 14 00:04:31.016230 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] self._affected_rows = self._read_query_result(unbuffered=unbuffered)
[Sat Sep 14 00:04:31.016241 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result
[Sat Sep 14 00:04:31.016251 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] result.read()
[Sat Sep 14 00:04:31.016262 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read
[Sat Sep 14 00:04:31.016273 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] first_packet = self.connection._read_packet()
[Sat Sep 14 00:04:31.016297 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/connections.py", line 674, in _read_packet
[Sat Sep 14 00:04:31.016310 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] recv_data = self._read_bytes(bytes_to_read)
[Sat Sep 14 00:04:31.016321 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] File "/var/www/xxxx/venv/lib/python3.6/site-packages/pymysql/connections.py", line 688, in _read_bytes
[Sat Sep 14 00:04:31.016332 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] self._sock.settimeout(self._read_timeout)
[Sat Sep 14 00:04:31.016342 2019] [wsgi:error] [pid 4693:tid 140670017648384] [remote 66.249.66.44:60013] AttributeError: 'NoneType' object has no attribute 'settimeout'
This settimeout is happening from time to time. I noticed people saying I should connect and close connection to make it single thread safy.
self.conn = self.create_connection()
cursor = self.conn.cursor()
query = ''' SELECT MY QUERY '''.format(self.xxxColumn, self.xxxColumn)
cursor.execute(query, t)
result = cursor.fetchall()
cursor.close()
self.close_connection()
Above shows how I am handling it. I added the following to my SQL:
connect_timeout = 200
read_timeout = 200
write_timeout = 200
max_allowed_packet = 1073741824
But I still keep having this error!
self._sock
isNone
so maybe your connection is not open. – Ungulate