密码中带有 @ 符号的 Oracle 连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25767485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle connection string with at sign @ in pasword
提问by Trinh Hoang Nhu
I have a code that connect to oracle using connection string:
我有一个使用连接字符串连接到 oracle 的代码:
conn = cx_Oracle.connect('username/password@server:port/services')
But the problem is my password contain @ character so it may become
但问题是我的密码包含@ 字符,所以它可能会变成
conn = cx_Oracle.connect('username/p@ssword@server:port/services')
it return
它返回
DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified
数据库错误:ORA-12154:TNS:无法解析指定的连接标识符
I use Django with Oracle with this settings
我将 Django 与 Oracle 与此设置一起使用
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'Services',
'USER': 'user',
'PASSWORD': 'p@ssword',
'HOST': 'ip',
'PORT': 'port',
}
}
I cant change password :( Does anyone know this problem?
我无法更改密码:(有人知道这个问题吗?
回答by Shashank Agarwal
I haven't tried cx_Oracle, but you might be able to connect by specifying the individual parameters -
我还没有尝试过 cx_Oracle,但是您可以通过指定各个参数来进行连接 -
conn = cx_Oracle.connect(user='username', password='p@ssword', dsn='server:port/services')
OR
或者
dsn_tns = cx_Oracle.makedsn('server', 'port', 'services')
conn = cx_Oracle.connect(user='username', password='p@ssword', dsn=dsn_tns)
回答by Sahil Chhabra
You can use any of the following way based on Service Name
or SID
whatever you have.
您可以根据Service Name
或SID
您拥有的任何方式使用以下任何一种方式。
With SID:
使用 SID:
dsn_tns = cx_Oracle.makedsn('server', 'port', 'sid')
conn = cx_Oracle.connect(user='username', password='p@ssword', dsn=dsn_tns)
OR
或者
With Service Name:
与服务名称:
dsn_tns = cx_Oracle.makedsn('server', 'port', service_name='service_name')
conn = cx_Oracle.connect(user='username', password='p@ssword', dsn=dsn_tns)
回答by Shane
回答by Wernfried Domscheit
Does this work?
这行得通吗?
conn = cx_Oracle.connect('username/"p@ssword"@server:port/services')