Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1622 มุมมอง
Hello, I am trying to execute this code from a server action but it is returning an error and I can't find how to solve it.

for record in records:

  if record.x_disponibilidad:   

    import psicopg2

    host = "localhost"

    port = "5432"

    user = "postgres"

    pas = "postgres"

    db = "SAG070524"

        

    connection_conf = """ 

        host=%s user=%s password=%s dbname=%s 

        """ % (host,port,pas,db)

        

    connection = psicopg2.connect(connection_conf)

    cursor = connection.cursor()

      

    query="update x_reg_asignaciones set x_sec = 1"

    cursor.execute(query)

    cursor.close()

    connection.close()

This is the error that is returning me

forbidden opcode(s) in 'for record in records:\n if record.x_disponibilidad: \n import psicopg2\n host = "localhost"\n port = "5432"\n user = "postgres"\n pas = "postgres"\n db = "SAG070524"\n \n connection_conf = """ \n host=%s user=%s password=%s dbname=%s \n """ % (host,port,pas,db)\n \n connection = psicopg2.connect(connection_conf)\n cursor = connection.cursor()\n \n query="update x_reg_asignaciones set x_sec = 1"\n cursor.execute(query)\n cursor.close()\n connection.close()': IMPORT_NAME


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

The error message is related to the IMPORT_NAME opcode. It seems like you’re trying to import the psycopg2 module inside a loop, which is generally not recommended and could be causing this error. Also please check the spelling of the import statement.


Refer to the code below:


import psycopg2


for record in records:

    if record.x_disponibilidad:

        host = "localhost"

        port = "5432"

        user = "postgres"

        pas = "postgres"

        db = "SAG070524"


        connection_conf = """

        host=%s user=%s password=%s dbname=%s

        """ % (host,port,pas,db)


        connection = psycopg2.connect(connection_conf)

        cursor = connection.cursor()


        query="update x_reg_asignaciones set x_sec = 1"

        cursor.execute(query)

        cursor.close()

        connection.close()


Hope it helps

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 24
1408
2
ก.ค. 22
5017
Odoo 11 - Python module search แก้ไขแล้ว
2
มี.ค. 21
2742
Import py file of a custom module แก้ไขแล้ว
1
มี.ค. 21
18469
0
ธ.ค. 23
1341