I am trying to parse arguments of database connection using argparse
module in python from jupyter notebook.
Looked into this link : Argparse in Jupyter Notebook throws a TypeError
Please let me know if its duplicate question as I couldn't find the solution.
Here is the code:
parser = argparse.ArgumentParser(description='This script is used to create schemas in database with default privileges')
parser.add_argument("--dbname", "-d", default='abcd', help="Database Name")
parser.add_argument("--hostname", "-H", help="database Hostname")
parser.add_argument("--port", "-P",help="database Port")
parser.add_argument("--username", "-u", help="database Username")
parser.add_argument("--password", "-p", help="database Password")
args = parser.parse_args()
Error:
usage: ipykernel_launcher.py [-h] [--dbname DBNAME] [--hostname HOSTNAME]
[--port PORT] [--username USERNAME]
[--password PASSWORD]
ipykernel_launcher.py: error: unrecognized arguments: -f
C:\*\*\AppData\Roaming\jupyter\runtime\kernel-def059d8-35af-4659-a9b2-a295f094ec66.json
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
Once this is done then I will pass this in this code:
conn = psycopg2.connect(database=dbname,
host=hostname,
port=port,
user=username,
password=password,
sslmode='require')
Please let me know how to resolve this.