I know this question has probably been answered but I can't seem to find the solution to my issue. I am using this method in my class and it expects one more argument as it doesn't seem to account for "self".
import cx_Oracle
import os
class Oracle(object):
def connect(self, username, password, hostname, port, sid):
""" Connect to the database. """
try:
dsn = cx_Oracle.makedsn(host=hostname, sid=sid, port=port)
self.db = cx_Oracle.connect(username, password, dsn)
except cx_Oracle.DatabaseError as e:
# Log
raise
# If the database connection succeeded create the cursor
# we-re going to use.
self.cursor = self.db.cursor()
Now, if I execute
oracle = Oracle.connect(os.environ.get('db_user'), os.environ.get('db_pw'), 'itd-dbx-sbox', 1521, 'sbox')
I will get the following error:
TypeError: connect() missing 1 required positional argument: 'sid'
What am I doing wrong? Sorry, I am new to this. Thanks for your help!
CodePudding user response:
connect
is an instance method, so you have to call the connect
method with an instance of Oracle
.
>>> oracle = Oracle()
>>> oracle.connect(<PARAM>)
This will automatically set self
as the current passed instance(oracle
) .