콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1972 화면
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

아바타
취소
관련 게시물 답글 화면 활동
0
2월 24
1694
2
7월 22
5406
2
3월 21
2984
1
3월 21
18863
0
12월 23
1559