C4W4Lab1 - database connection error

  • Anybody got errors here? when testing the connection from the Notebook to the Postgres database
  • postgresql+psycopg2://postgresuser:***@de-c4w4lab1-rds.ctce40w4g8aw.us-east-1.rds.amazonaws.com:5432/postgres
    5 rows affected.

KeyError Traceback (most recent call last)
Cell In[19], line 1
----> 1 get_ipython().run_cell_magic(‘sql’, ‘’, ‘\nSELECT schema_name\nFROM information_schema.schemata;\n’)

File ~/workspace/jupyterlab-venv/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2541, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2539 with self.builtin_trap:
2540 args = (magic_arg_s, cell)
→ 2541 result = fn(*args, **kwargs)
2543 # The code below prevents the output from being displayed
2544 # when using magics with decorator @output_can_be_silenced
2545 # when the last Python token in the expression is a ‘;’.
2546 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/workspace/jupyterlab-venv/lib/python3.10/site-packages/sql/magic.py:219, in SqlMagic.execute(self, line, cell, local_ns)
216 return
218 try:
→ 219 result = sql.run.run(conn, parsed[“sql”], self, user_ns)
221 if (
222 result is not None
223 and not isinstance(result, str)
(…)
226 # Instead of returning values, set variables directly in the
227 # user’s namespace. Variable names given by column names
229 if self.autopandas:

File ~/workspace/jupyterlab-venv/lib/python3.10/site-packages/sql/run.py:374, in run(conn, sql, config, user_namespace)
372 if result and config.feedback:
373 print(interpret_rowcount(result.rowcount))
→ 374 resultset = ResultSet(result, config)
375 if config.autopandas:
376 return resultset.DataFrame()

File ~/workspace/jupyterlab-venv/lib/python3.10/site-packages/sql/run.py:116, in ResultSet.init(self, sqlaproxy, config)
114 list.init(self, sqlaproxy.fetchall())
115 self.field_names = unduplicate_field_names(self.keys)
→ 116 self.pretty = PrettyTable(self.field_names, style=prettytable.dict[config.style.upper()])
117 else:
118 list.init(self, )

KeyError: ‘DEFAULT’

Hello @Libby609 someone had a similar error in C4W1 first practice lab. It might help you if you add this code from post. Thank you

1 Like

Thanks @Georgios Yes, it works now after adding that code.

1 Like