获取cx_Oracle.DatabaseError:ORA-12170:TNS:在Google Cloud Platform的Composer中创建气流作业时发生了连接超时
我尝试了以下两个代码,但是它们没有用。
engine = cx_Oracle.connect('user','pass',cx_Oracle.makedsn('hostip','portnum',None,'service_name'))
engine = cx_Oracle.connect('user / pass @ hostip:portnum / service_name')
def get_oracle_engine():
oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{hostname}:{port}/{service_name}'
oracle_host = 'hostip'
oracle_port = 'portnum'
oracle_user = 'user'
oracle_pw = 'pass'
oracle_service_name = 'service_name'
engine = cx_Oracle.connect(oracle_connection_string.format(
username=oracle_user,
password=oracle_pw,
hostname=oracle_host,
port=oracle_port,
service_name=oracle_service_name ,
))
return engine
engine = get_engine()
logging.info("connected..")
环境:Google Cloud Platform-Composer,Airflow,Oracle
它应该连接到Oracle数据库。有什么建议吗?
答案 0 :(得分:0)
连接超时是指oracle客户端无法访问oracle_host
。因此请注意,必须从正在使用的作曲家环境中访问Oracle服务器。要测试连通性:
gcloud container clusters get-credentials <GKE_Cluster_used_by_Composer> \
--zone=<Composer_Zone> \
--project=<PROJECT_ID>
kubectl run --generator=run-pod/v1 --image=nginx:alpine test
kubectl exec -ti test sh
/ # nc -zv <oracle_host> <oracle_port>
如果一切正常,您应该会得到以下信息:
kubectl exec -ti test sh
/ # nc -zv myorchost.internal.net 53701
myorchost.internal.net (10.0.0.11:53701) open