dawncold
2017-09-21 20:39:32 +08:00
我们项目是这样连接的,你试试
```python
def _get_conn(self):
os.environ['NLS_LANG'] = 'AMERICAN_CHINA.UTF8'
conn = None
connection_string = '{}/{}@{}'.format(self.user, self.password, cx_Oracle.makedsn(self.host, self.port, self.database))
try:
conn = cx_Oracle.connect(connection_string)
conn.outputtypehandler = OracleAdapter.output_type_handler
conn.autocommit = True
if self.schema:
conn.current_schema = str(self.schema) # TODO: current_schema requires str, complains against unicode, may be fixed in new release
except:
LOGGER.critical('Cannot connect to database: %(parameters)s', {'parameters': self}, exc_info=1)
try:
raise
finally:
if conn is not None:
try:
conn.close()
except Exception:
LOGGER.exception('Cannot close database connection')
else:
return conn
```