1

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 every cur.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.

pjshap
  • 72
  • 11
  • Wild guess: Some overzealous firewall or other such thing is injecting reset packets and causing your connections to drop. – Kevin Apr 23 '15 at 17:49
  • Alright, I'll see if IT can check if something like that is going on. – pjshap Apr 23 '15 at 18:00
  • So IT gave me access to the pg logs, which said: `< 2015-04-23 11:47:10.259 EDT >LOG: could not receive data from client: Connection reset by peer < 2015-04-23 11:47:10.259 EDT >LOG: unexpected EOF on client connection with an open transaction` I googled these messages and didn't get much new information. – pjshap Apr 23 '15 at 19:54
  • 1
    Some router or other networked device between your client application and the database server is injecting reset packets. This causes the "Connection reset by peer" error. It's also possible your network is very flaky and/or slow. – Kevin Apr 23 '15 at 21:12

0 Answers0