Thanks to JoshuaBoshi for his answer, which solved the problem. After calling the procedure, I had to close the cursor and open it again before using it to execute another statement:
cursor.close()
cursor = connection.cursor()
The cursor can be closed immediately after fetchall()
. The result set still remains and can be looped through.