在 Python 中使用 teradatasql 模块连接到 Teradata

2024-03-18

我正在尝试使用 Python 中的 teradatasql 模块连接到 Teradata。该代码在本地主机上运行良好,但是一旦作为服务器代码的一部分部署在服务器上,就会抛出错误。

代码:

import teradatasql
try:
    host, username, password = 'hostname', 'username', '****'
    session = teradatasql.connect(host=host, user=username, password=password, logmech="LDAP")

except Exception as e:
    print(e)

我在服务器上遇到错误:

[版本 16.20.0.60] [会话 0] [Teradata SQL 驱动程序] 在 gosqldriver/teradatasql 处接收配置响应消息标头↵失败。 (*teradataConnection).makeDriverError TeradataConnection.go:1101↵ 位于 gosqldriver/teradatasql。 (*teradataConnection).sendAndReceive TeradataConnection.go:1397↵ 位于 gosqldriver/teradatasql.newTeradataConnection TeradataConnection.go:180↵ 位于 gosqldriver/teradatasql.(*teradataDriver)。 在数据库/sql.dsnConnector.Connect sql.go:600↵ 在数据库/sql.(*DB).conn sql.go:1103↵ 在数据库/sql 打开 TeradataDriver.go:32↵。 (*DB).Conn sql.go:1619↵ 位于 main.goCreateConnection goside.go:275↵ 位于 main. _cgoexpwrap_212fad278f55_goCreateConnection _cgo_gotypes.go:240↵在runtime.call64 asm_amd64.s:574↵在runtime.cgocallbackg1 cgocall.go:316↵在runtime.cgocallbackg cgocall.go:194↵在runtime.cgocallback_gofunc asm_amd64 .s:826↵ 在运行时。 goexit asm_amd64.s:2361↵由于读取 tcp IP:PORT->IP:PORT: wsarecv: 现有连接被远程主机强制关闭


概述了此错误的根本原因通过托姆诺兰:

The stack trace indicates that a TCP socket connection was made to the database, then the driver transmitted a Config Request message to the database, then the driver timed out waiting for a Config Response message from the database.

换句话说,驱动程序认为它已经建立了 TCP 套接字连接,但 TCP 套接字连接可能并未完全成功,因为驱动程序和数据库之间的初始消息握手发生了故障。

最可能的原因是某种网络问题阻止驱动程序正确连接到数据库。

我今天遇到了这个问题,并通过更改主机解决了它。我也在 VPN 上,发现 DNS 中的实际主机名不起作用,但可用的 ALIAS 起作用。例如在 Windows 上:

C:\WINDOWS\system32>nslookup MYDB-TEST # <-- works
Server:  abcd.domain.com
Address: <OMITTED>
Name:    MYDB.domain.com # <-- doesn't work
Address:  <OMITTED>
Aliases:  mydb-test.domain.com # <-- works

我认识到这可能是一个特定的解决方案选项,可能并不适合所有人,但根据我的经验,问题的根源被确认为 TCP 连接问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Python 中使用 teradatasql 模块连接到 Teradata 的相关文章

随机推荐