使用Python中的TeradasQL模块连接到Teradata

2024-06-16 12:28:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python中的TeradasQL模块连接到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)

我进入服务器时出错:

[Version 16.20.0.60] [Session 0] [Teradata SQL Driver] Failure receiving Config Response message header↵ at gosqldriver/teradatasql. (*teradataConnection).makeDriverError TeradataConnection.go:1101↵ at gosqldriver/teradatasql. (*teradataConnection).sendAndReceive TeradataConnection.go:1397↵ at gosqldriver/teradatasql.newTeradataConnection TeradataConnection.go:180↵ at gosqldriver/teradatasql.(*teradataDriver). Open TeradataDriver.go:32↵ at database/sql.dsnConnector.Connect sql.go:600↵ at database/sql.(*DB).conn sql.go:1103↵ at database/sql. (*DB).Conn sql.go:1619↵ at main.goCreateConnection goside.go:275↵ at main. _cgoexpwrap_212fad278f55_goCreateConnection _cgo_gotypes.go:240↵ at runtime.call64 asm_amd64.s:574↵ at runtime.cgocallbackg1 cgocall.go:316↵ at runtime.cgocallbackg cgocall.go:194↵ at runtime.cgocallback_gofunc asm_amd64.s:826↵ at runtime.goexit asm_amd64.s:2361↵Caused by read tcp IP:PORT->IP:PORT: wsarecv: An existing connection was forcibly closed by the remote host


Tags: 代码hostgosqlusernamepassworddatabaseamd64
1条回答
网友
1楼 · 发布于 2024-06-16 12:28:05

tomnolan概述了此错误的根本原因here

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.

In other words, the driver thought that it had established a TCP socket connection, but the TCP socket connection was probably not fully successful, because a failure occurred on the initial message handshake between the driver and the database.

The most likely cause is that some kind of networking problem prevented the driver from properly connecting to the database.

我今天遇到了这个问题,通过更换主机解决了这个问题。我也在VPN上,发现DNS中的实际主机名不起作用,但可用的别名起作用。例如,在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连接问题

相关问题 更多 >