langchain DOC: Remove try/catch blocks from sample connection code to allow actual error to be shown

1tu0hz3e  于 24天前  发布在  其他
关注(0)|答案(3)|浏览(19)

URL

https://github.com/langchain-ai/langchain/blob/master/cookbook/oracleai_demo.ipynb

待办事项清单:

  • 为这个问题添加了一个非常描述性的标题。
  • 如果适用,我包含了一个指向我参考的文档页面的链接。

当前文档的问题:

https://github.com/langchain-ai/langchain/blob/master/cookbook/oracleai_demo.ipynb 中的示例代码使用了 try/catch 块,但它们没有打印实际的驱动程序或数据库错误,这使得无法进行故障排除。例如,它目前有:

import sys

import oracledb

# please update with your username, password, hostname and service_name
username = ""
password = ""
dsn = ""

try:
    conn = oracledb.connect(user=username, password=password, dsn=dsn)
    print("Connection successful!")
except Exception as e:
    print("Connection failed!")
    sys.exit(1)

对于任何连接失败,这将只显示:

Connection failed!

代码应该更改为:

import sys

import oracledb

# please update with your username, password, hostname and service_name
username = ""
password = ""
dsn = ""

conn = oracledb.connect(user=username, password=password, dsn=dsn)
print("Connection successful!")

例如,使用错误的密码时,这将显示回溯和有用的错误信息:

oracledb.exceptions.DatabaseError: ORA-01017: invalid credential or not authorized; logon denied
Help: https://docs.oracle.com/error-help/db/ora-01017/

其他示例中也存在相同的 try/catch 问题。

关于内容的想法或请求:

  • 无响应*
1cosmwyk

1cosmwyk1#

我想要处理这个问题。你能给我分配一下问题#22410吗?

44u64gxh

44u64gxh2#

@isatyamks 我没有权限分配它。

yr9zkbsy

yr9zkbsy3#

#22635
The outer try/except block handles connection errors, and the inner try/except block handles SQL execution errors, providing detailed error messages for both.
try:
conn = oracledb.connect(user=username, password=password, dsn=dsn)
print("Connection successful!")
cursor = conn.cursor()
try:
cursor.execute(
"""
begin
-- Drop user
begin
execute immediate 'drop user testuser cascade';
exception
when others then
dbms_output.put_line('Error dropping user: ' || SQLERRM);
end;
@cjbj I hope this change will work...

相关问题