本文整理汇总了Python中cx_Oracle.makedsn方法的典型用法代码示例。如果您正苦于以下问题:Python cx_Oracle.makedsn方法的具体用法?Python cx_Oracle.makedsn怎么用?Python cx_Oracle.makedsn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cx_Oracle
的用法示例。
在下文中一共展示了cx_Oracle.makedsn方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def connect(self):
self.initConnection()
self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
self.__dsn = utf8encode(self.__dsn)
self.user = utf8encode(self.user)
self.password = utf8encode(self.password)
try:
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
logger.info("successfully connected as SYSDBA")
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), ex:
if "Oracle Client library" in str(ex):
msg = re.sub(r"DPI-\d+:\s+", "", str(ex))
msg = re.sub(r': ("[^"]+")', r" (\g<1>)", msg)
msg = re.sub(r". See (http[^ ]+)", r'. See "\g<1>"', msg)
raise SqlmapConnectionException(msg)
try:
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
raise SqlmapConnectionException(msg)
示例2: execute
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def execute(self, host, port='1521', user='', password='', sid='', service_name=''):
if sid:
dsn = cx_Oracle.makedsn(host=host, port=port, sid=sid)
elif service_name:
dsn = cx_Oracle.makedsn(host=host, port=port, service_name=service_name)
else:
raise ValueError('Options sid and service_name cannot be both empty')
try:
with Timing() as timing:
fp = cx_Oracle.connect(user, password, dsn, threaded=True)
code, mesg = '0', fp.version
except cx_Oracle.DatabaseError as e:
code, mesg = e.args[0].message[:-1].split(': ', 1)
return self.Response(code, mesg, timing)
# }}}
# PostgreSQL {{{
示例3: db_connect
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def db_connect(args):
if args.type == "mysql" or args.type == "mariadb":
import mysql.connector
try:
connection = mysql.connector.connect(
user=args.user,
password=args.password,
database=args.db)
except mysql.connector.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "mssql":
import pymssql
try:
connection = pymssql.connect(server="localhost", database=args.db)
except pymssql.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "pgsql":
import psycopg2
try:
connection = psycopg2.connect(
"dbname='{}' user='{}' password='{}'".format(
args.db, args.user, args.password))
except psycopg2.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
elif args.type == "oracle":
import cx_Oracle
try:
connection = cx_Oracle.connect(
args.user, args.password, cx_Oracle.makedsn(
'127.0.0.1', 1521, args.db), mode=cx_Oracle.SYSDBA)
except cx_Oracle.Error as err:
print(colorize("red", "[ERROR] {}".format(err)))
return None
return connection
示例4: _connect_string
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def _connect_string(self):
settings_dict = self.settings_dict
if not settings_dict['HOST'].strip():
settings_dict['HOST'] = 'localhost'
if settings_dict['PORT'].strip():
dsn = Database.makedsn(settings_dict['HOST'],
int(settings_dict['PORT']),
settings_dict['NAME'])
else:
dsn = settings_dict['NAME']
return "%s/%s@%s" % (settings_dict['USER'],
settings_dict['PASSWORD'], dsn)
示例5: __init__
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def __init__(self, **keywords):
import cx_Oracle as db
if 'pw' in keywords:
keywords['password'] = keywords.pop('pw')
#@@ TODO: use db.makedsn if host, port is specified
keywords['dsn'] = keywords.pop('db')
self.dbname = 'oracle'
db.paramstyle = 'numeric'
self.paramstyle = db.paramstyle
# oracle doesn't support pooling
keywords.pop('pooling', None)
DB.__init__(self, db, keywords)
示例6: __init__
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def __init__(self, **keywords):
import cx_Oracle as db
if 'pw' in keywords:
keywords['password'] = keywords.pop('pw')
#@@ TODO: use db.makedsn if host, port is specified
keywords['dsn'] = keywords.pop('db')
self.dbname = 'oracle'
db.paramstyle = 'numeric'
self.paramstyle = db.paramstyle
# oracle doesn't support pooling
keywords.pop('pooling', None)
DB.__init__(self, db, keywords)
示例7: _connect_string
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def _connect_string(self):
settings_dict = self.settings_dict
if not settings_dict['HOST'].strip():
settings_dict['HOST'] = 'localhost'
if settings_dict['PORT']:
dsn = Database.makedsn(settings_dict['HOST'],
int(settings_dict['PORT']),
settings_dict['NAME'])
else:
dsn = settings_dict['NAME']
return "%s/%s@%s" % (settings_dict['USER'],
settings_dict['PASSWORD'], dsn)
示例8: test_get_conn_sid
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def test_get_conn_sid(self, mock_connect):
dsn_sid = {'dsn': 'dsn', 'sid': 'sid'}
self.connection.extra = json.dumps(dsn_sid)
self.db_hook.get_conn()
assert mock_connect.call_count == 1
args, kwargs = mock_connect.call_args
self.assertEqual(args, ())
self.assertEqual(kwargs['dsn'],
cx_Oracle.makedsn(dsn_sid['dsn'],
self.connection.port, dsn_sid['sid']))
示例9: test_get_conn_service_name
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def test_get_conn_service_name(self, mock_connect):
dsn_service_name = {'dsn': 'dsn', 'service_name': 'service_name'}
self.connection.extra = json.dumps(dsn_service_name)
self.db_hook.get_conn()
assert mock_connect.call_count == 1
args, kwargs = mock_connect.call_args
self.assertEqual(args, ())
self.assertEqual(kwargs['dsn'], cx_Oracle.makedsn(
dsn_service_name['dsn'], self.connection.port,
service_name=dsn_service_name['service_name']))
示例10: connect
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def connect(self):
self.initConnection()
self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
self.__dsn = utf8encode(self.__dsn)
self.user = utf8encode(self.user)
self.password = utf8encode(self.password)
try:
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
logger.info("successfully connected as SYSDBA")
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
try:
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
raise SqlmapConnectionException(msg)
示例11: _dsn
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def _dsn(self):
settings_dict = self.settings_dict
if not settings_dict['HOST'].strip():
settings_dict['HOST'] = 'localhost'
if settings_dict['PORT']:
return Database.makedsn(settings_dict['HOST'], int(settings_dict['PORT']), settings_dict['NAME'])
return settings_dict['NAME']
示例12: get_connection
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def get_connection(self, db_name=None):
if self.conn:
return self.conn
if self.sid:
dsn = cx_Oracle.makedsn(self.host, self.port, self.sid)
self.conn = cx_Oracle.connect(self.user, self.password, dsn=dsn, encoding="UTF-8", nencoding="UTF-8")
elif self.service_name:
dsn = cx_Oracle.makedsn(self.host, self.port, service_name=self.service_name)
self.conn = cx_Oracle.connect(self.user, self.password, dsn=dsn, encoding="UTF-8", nencoding="UTF-8")
else:
raise ValueError('sid 和 dsn 均未填写, 请联系管理页补充该实例配置.')
return self.conn
示例13: conn_oracle
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def conn_oracle(self):
self.data = self.conlist
try:
tns_name = cx_Oracle.makedsn(self.conlist[2], self.conlist[3], "%s"%self.xe)
db = cx_Oracle.connect(self.conlist[0],self.conlist[1], tns_name)
return db
except:
self.col.printGreen(u"warning!!!!!!!!!!!!!!!!!!!\n程序出错!\n")
print "\n"
self.col.printRed(u"脚本连接服务器失败 ,请检查的你的用户名以及密码。或者是否数据库开启权限外链!")
sys.exit()
示例14: check_statue
# 需要导入模块: import cx_Oracle [as 别名]
# 或者: from cx_Oracle import makedsn [as 别名]
def check_statue(self):
"""
@函数方法:检测错误
:return:
"""
self.data = self.conlist
try:
tns_name = cx_Oracle.makedsn(self.conlist[2], self.conlist[3], "%s"%self.xe)
cx_Oracle.connect(self.conlist[0], self.conlist[1], tns_name)
return (10086, 'access')
except Exception as e:
return e