Пытаюсь закинуть данные в таблицу. Создать её получилось, но при закидывании данных выходит Attributeerror: __enter__
try:
con = psycopg2.connect(
host = host,
user = user,
password = password,
database = db_name
)
con.autocommit = True
cur = con.cursor()
with state.proxy() as data:
ncity = cur.execute(f"""DELETE FROM native_city WHERE user_id = {user_id}""")
ncity = cur.execute("""INSERT INTO native_city (user_id, city, area) VALUES ({}, {}, {})""", (data['user_id'], data['citynative'], data['areanative']))
return ncity
except Exception as _ex:
print('[INFO] Error while working with PostgreSQL', _ex)
finally:
if con:
cur.close()
con.close()
print('[INFO] PostgreSQL connection closed')