I'm using pg8000 to interact with a postgresql database in a python script. I keep getting an error like the following, though not at the same line every time:
Traceback (most recent call last):
File "C:\Users\myname\workspace2\anaconda_scripts\file_name.py", line 311, in <module>
object_name.method_name(cur)
File "C:\Users\myname\workspace2\anaconda_scripts\file_name.py", line 134, in method_name
conn.commit()
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\pg8000\core.py", line 1398, in commit
self.execute(self._cursor, "commit", None)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\pg8000\core.py", line 1684, in execute
self.handle_messages(cursor)
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\pg8000\core.py", line 1757, in handle_messages
self._close()
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\pg8000\core.py", line 1419, in _close
self._flush()
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
I don't know much about sockets, so I've tried/checked the following:
- Added
conn.commit()
after everycur.execute()
in the code - Instead of
select *
in the execute statement, I selected only the columns I needed - I made sure that I included
cur.close() conn.close()
at the end of the script
Does anyone have any suggestions or insight about pg8000 that would help me figure out what other aspects of the script to look into? I have searched the specific error, but all of the questions/answers seem to be about interacting with the sockets directly, and I'm using sockets indirectly through pg8000. Any help would be greatly appreciated, thanks.