python 无法使用pyhdb执行查询

vhipe2zx  于 2023-01-29  发布在  Python
关注(0)|答案(2)|浏览(117)

我正在尝试使用pyhdb执行一个简单的查询。
下面是我的代码:

HDB_TRACE=1

import pyhdb as db

db.tracing = True

connection = db.connect('HOST', 31047, 'USER', 'PASSWORD')

cursor = connection.cursor()

cursor.execute("SELECT TOP 1 GLOBAL_BRAND_OWNER FROM _SYS_BIC.LAV_DWH_SELLOUT.CV_NIELSEN")

print(cursor.fetchone())

我得到的错误是
pyhdb.exceptions.DatabaseError:权限不足:未获授权
我问了数据库管理员,他告诉我,我登录的用户拥有所有可能的权限。
如果我尝试SELECT 'Hello Python World' FROM DUMMY,它可以工作。我不知道我的代码中是否有错误。
如果我使用同一用户通过HANA Studio执行查询,它会工作。
以下是该过程的轨迹:

C:\Users\grellaa\AppData\Local\Programs\Python\Python35\python.exe D:/ProgettoTableau/Importazione_Variabile_Obiettivo.py
RequestMessage = {
    header = [
        session_id = -1,
        packet_count = 0,
        payload_length = 128,
        varpartsize = 131040,
        num_segments = 1,
        packet_options = 0
    ],
    segments = [
        RequestSegment = {
            header = [
                segment_length = 128,
                segment_offset = 0,
                num_parts = 1,
                segment_number = 1,
                segment_kind = 1,
                message_type = 65,
                commit = 0,
                command_options = 0
            ],
            parts = [
                Authentication = {
                    header = [
                        part_kind = 33,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 88,
                        remaining_buffer_size = 131016
                    ],
                    trace_header = b'21 00 01 00 00 00 00 00 58 00 00 00 c8 ff 01 00',
                    trace_payload = b'03 00 08 31 30 30 30 43 30 32 39 0b 53 43 52 41 4d 53 48 41 32 35 36 40 77 a3 f6 c2 cb a6 ...',
                    user = '1000C029',
                    methods = {b'SCRAMSHA256': b'w\xa3\xf6\xc2\xcb\xa6v\xb0\x9a\xf0\x7f\xf4g\x07\x0ep]B{\xef\x99L-vc\x94\xeb2=\xe4\x13\xa7\xdb:\x87\xb10\x0c\xb2*\x0esYY\xed7\x19\x81OU\xd2\x95R\x95\x16W\xbb\xdfS\xe0\x04\xac\xb1\xe6'}
                }
            ]
        }
    ]
}
ReplyMessage = {
    header = [
        session_id = 0,
        packet_count = 0,
        payload_length = 128,
        varpartsize = 29968,
        num_segments = 1,
        packet_options = 0
    ],
    segments = [
        ReplySegment = {
            header = [
                segment_length = 128,
                segment_offset = 0,
                num_parts = 1,
                segment_number = 1,
                segment_kind = 2,
                function_code = 0
            ],
            parts = [
                Authentication = {
                    header = [
                        part_kind = 33,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 83,
                        remaining_buffer_size = 29928
                    ],
                    trace_header = b'21 00 01 00 00 00 00 00 53 00 00 00 e8 74 00 00',
                    trace_payload = b'02 00 0b 53 43 52 41 4d 53 48 41 32 35 36 44 02 00 10 c4 0a c3 2b 27 be cc b3 c4 65 ab 1b ...',
                    user = None,
                    methods = {b'SCRAMSHA256': b"\x02\x00\x10\xc4\n\xc3+'\xbe\xcc\xb3\xc4e\xab\x1bb\x16_80!$Y\xe2*5\xfe\x14#2+\x10\x06@\x05\x0b2l\xc3\xe2\x92\x94\x80\xbc\x80\x96[y\x04&\xe8\x1fR?z\xbe\x1b\xd6\xcbp\x0b\xdf&\x9a+s\x8c\x85"}
                }
            ]
        }
    ]
}
RequestMessage = {
    header = [
        session_id = 0,
        packet_count = 0,
        payload_length = 208,
        varpartsize = 131040,
        num_segments = 1,
        packet_options = 0
    ],
    segments = [
        RequestSegment = {
            header = [
                segment_length = 208,
                segment_offset = 0,
                num_parts = 3,
                segment_number = 1,
                segment_kind = 1,
                message_type = 66,
                commit = 0,
                command_options = 0
            ],
            parts = [
                Authentication = {
                    header = [
                        part_kind = 33,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 59,
                        remaining_buffer_size = 131016
                    ],
                    trace_header = b'21 00 01 00 00 00 00 00 3b 00 00 00 c8 ff 01 00',
                    trace_payload = b'03 00 08 31 30 30 30 43 30 32 39 0b 53 43 52 41 4d 53 48 41 32 35 36 23 00 01 20 7d 35 0f ...',
                    user = '1000C029',
                    methods = {'SCRAMSHA256': b'\x00\x01 }5\x0f\x02\x15\xf4|`\x985\xc9s\xc9\xd5\xd5J\xbd!\xdb\xc9\x9bL\x91\x8f\x99\xfd\xed:e\x89 \xee'}
                },
                ClientId = {
                    header = [
                        part_kind = 35,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 23,
                        remaining_buffer_size = 130936
                    ],
                    trace_header = b'23 00 01 00 00 00 00 00 17 00 00 00 78 ff 01 00',
                    trace_payload = b'70 79 68 64 62 2d 36 30 37 32 40 73 64 67 6e 62 32 38 35 2e 53 44 47 00',
                    client_id = 'pyhdb-6072@sdgnb285.SDG'
                },
                ConnectOptions = {
                    header = [
                        part_kind = 42,
                        part_attributes = 0,
                        argument_count = 8,
                        bigargument_count = 0,
                        payload_size = 42,
                        remaining_buffer_size = 130896
                    ],
                    trace_header = b'2a 00 08 00 00 00 00 00 2a 00 00 00 50 ff 01 00',
                    trace_payload = b'03 1d 05 00 65 6e 5f 55 53 02 1c 01 17 03 01 00 00 00 0c 03 01 00 00 00 0f 03 00 00 00 00 ...'
                }
            ]
        }
    ]
}
ReplyMessage = {
    header = [
        session_id = 1718090968109219,
        packet_count = 0,
        payload_length = 376,
        varpartsize = 29968,
        num_segments = 1,
        packet_options = 0
    ],
    segments = [
        ReplySegment = {
            header = [
                segment_length = 376,
                segment_offset = 0,
                num_parts = 3,
                segment_number = 1,
                segment_kind = 2,
                function_code = 0
            ],
            parts = [
                Authentication = {
                    header = [
                        part_kind = 33,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 15,
                        remaining_buffer_size = 29928
                    ],
                    trace_header = b'21 00 01 00 00 00 00 00 0f 00 00 00 e8 74 00',
                    trace_payload = b'02 00 0b 53 43 52 41 4d 53 48 41 32 35 36 00 00',
                    user = None,
                    methods = {b'SCRAMSHA256': b''}
                },
                ConnectOptions = {
                    header = [
                        part_kind = 42,
                        part_attributes = 0,
                        argument_count = 21,
                        bigargument_count = 0,
                        payload_size = 118,
                        remaining_buffer_size = 29896
                    ],
                    trace_header = b'2a 00 15 00 00 00 00 00 76 00 00 00 c8 74 00 00',
                    trace_payload = b'01 03 98 1a 06 00 0b 1d 03 00 48 4c 51 0c 03 01 00 00 00 17 03 01 00 00 00 10 03 06 00 00 ...'
                },
                TopologyInformation = {
                    header = [
                        part_kind = 15,
                        part_attributes = 0,
                        argument_count = 3,
                        bigargument_count = 0,
                        payload_size = 165,
                        remaining_buffer_size = 29760
                    ],
                    trace_header = b'0f 00 03 00 00 00 00 00 a5 00 00 00 40 74 00 00',
                    trace_payload = b'08 00 05 03 04 00 00 00 01 1d 0e 00 31 36 31 2e 32 37 2e 31 36 36 2e 31 30 32 02 03 47 79 ...'
                }
            ]
        }
    ]
}
RequestMessage = {
    header = [
        session_id = 1718090968109219,
        packet_count = 0,
        payload_length = 112,
        varpartsize = 131040,
        num_segments = 1,
        packet_options = 0
    ],
    segments = [
        RequestSegment = {
            header = [
                segment_length = 112,
                segment_offset = 0,
                num_parts = 1,
                segment_number = 1,
                segment_kind = 1,
                message_type = 2,
                commit = 0,
                command_options = 0
            ],
            parts = [
                Command = {
                    header = [
                        part_kind = 3,
                        part_attributes = 0,
                        argument_count = 1,
                        bigargument_count = 0,
                        payload_size = 72,
                        remaining_buffer_size = 131016
                    ],
                    trace_header = b'03 00 01 00 00 00 00 00 48 00 00 00 c8 ff 01 00',
                    trace_payload = b'53 45 4c 45 43 54 20 54 4f 50 20 31 20 47 4c 4f 42 41 4c 5f 42 52 41 4e 44 5f 4f 57 4e 45 ...',
                    sql_statement = 'SELECT TOP 1 GLOBAL_BRAND_OWNER FROM _SYS_BIC.LAV_DWH_SELLOUT.CV_NIELSEN'
                }
            ]
        }
    ]
}
Traceback (most recent call last):
  File "D:/ProgettoTableau/Importazione_Variabile_Obiettivo.py", line 9, in <module>
    cursor.execute("SELECT TOP 1 GLOBAL_BRAND_OWNER FROM _SYS_BIC.LAV_DWH_SELLOUT.CV_NIELSEN")
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\cursor.py", line 258, in execute
    self._execute_direct(statement)
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\cursor.py", line 217, in _execute_direct
    reply = self.connection.send_request(request)
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\connection.py", line 84, in send_request
    return self.__send_message_recv_reply(payload.getvalue())
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\connection.py", line 124, in __send_message_recv_reply
    return ReplyMessage.unpack_reply(header, payload)
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\protocol\message.py", line 92, in unpack_reply
    segments=tuple(ReplySegment.unpack_from(payload, expected_segments=header.num_segments)),
  File "C:\Users\grellaa\AppData\Roaming\Python\Python35\site-packages\pyhdb\protocol\segments.py", line 152, in unpack_from
    raise error.parts[0].errors[0]
pyhdb.exceptions.DatabaseError: insufficient privilege: Not authorized
chhkpiq4

chhkpiq41#

很明显,您的用户实际上并不拥有“所有可能的权限”。看到您试图访问计算视图,我的第一个猜测是您的用户没有该计算视图的授权。
要更全面地分析问题,您可以通过SAP HANA Studio登录,右键单击视图并选择“显示授权”。这将为您提供所需权限和已提供权限的图形概览。
这个blog post很好地介绍了如何使用这个工具。

pod7payv

pod7payv2#

您必须为登录到HANA数据库的游标对象设置参数,并确保用户对保存您正在查询的数据的模式具有权限。

相关问题