E
E
Elvis2020-04-06 23:22:41
Python
Elvis, 2020-04-06 23:22:41

How to overcome the "psycopg2.ProgrammingError..." error?

Hey!
I keep getting an error

psycopg2.ProgrammingError: execute cannot be used while an asynchronous query is underway

As I understand it, this is because I am trying to use the data while the request has not yet been completed. how can i fix it? I use something like this, if I shorten the code to just a visual example:
def wait(conn):
    while True:
        state = conn.poll()
        if state == psycopg2.extensions.POLL_OK:
            break
        elif state == psycopg2.extensions.POLL_WRITE:
            select.select([], [conn.fileno()], [])
        elif state == psycopg2.extensions.POLL_READ:
            select.select([conn.fileno()], [], [])
        else:
            raise psycopg2.OperationalError("poll() returned %s" % state)

try:
    aconn = psycopg2.connect(f"dbname='{db_name}' user='{db_user}' host='{db_host}' password='{db_pass}'", async_=1)
    wait(aconn)
    c = aconn.cursor()
except Exception as e:
    print('Нет соединения с базой:', str(e))

@socketio.on('uploaddata')
def on_send(data):
    id = data['id']
    lablvlid = data['lablvlID']
    player = data['player']
    s = f"select * from cart_plcl where id='{id}' and lablvlid ='{lablvlid}' and player='{player}'"
    c.execute(s)
    wait(c.connection)
    result = c.fetchall()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question