Oracle connection string with at sign @ in pasword

别说谁变了你拦得住时间么 提交于 2019-12-20 02:44:08

问题


I have a code that connect to oracle using connection string:

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

I use Django with Oracle with this settings

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?


回答1:


I haven't tried cx_Oracle, but you might be able to connect by specifying the individual parameters -

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)



回答2:


You can use any of the following way based on Service Name or SID whatever you have.

With 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)



回答3:


FYI: This was a long-standing bug in Django. The first stable version containing the fix is v2.1




回答4:


Does this work?

conn = cx_Oracle.connect('username/"p@ssword"@server:port/services')


来源:https://stackoverflow.com/questions/25767485/oracle-connection-string-with-at-sign-in-pasword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!