Error while connecting to DB from Notebook C4_W1_Lab_1

Hello while running C4_W1_Lab_1_Data_Normalization.ipynb i received the following error:

%%sql
select count(*) from classicmodels_obt.orders;

KeyError Traceback (most recent call last)
Cell In[6], line 1
----> 1 get_ipython().run_cell_magic(‘sql’, ‘’, ‘select count(*) from classicmodels_obt.orders;\n’)

File ~/environment/lab-venv/lib64/python3.9/site-packages/IPython/core/interactiveshell.py:2517, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
2515 with self.builtin_trap:
2516 args = (magic_arg_s, cell)
→ 2517 result = fn(*args, **kwargs)
2519 # The code below prevents the output from being displayed
2520 # when using magics with decorator @output_can_be_silenced
2521 # when the last Python token in the expression is a ‘;’.
2522 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/environment/lab-venv/lib64/python3.9/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 ~/environment/lab-venv/lib64/python3.9/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 ~/environment/lab-venv/lib64/python3.9/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’

1 Like

Hi, I got the same error but I fixed changing the table style with this command

%config SqlMagic.style = '_DEPRECATED_DEFAULT'

I think this is just a patch because is a “deprecated” key.
To see all available keys, I executed this command in a cell

import prettytable
print(prettytable.__dict__.keys())

and the result shows all available styles to DataFrame from sql query executed and other keys
dict_keys([‘name’, ‘doc’, ‘package’, ‘loader’, ‘spec’, ‘path’, ‘file’, ‘cached’, ‘builtins’, ‘annotations’, ‘Any’, ‘_version’, ‘version’, ‘prettytable’, ‘_DEPRECATED_ALL’, ‘_DEPRECATED_DEFAULT’, ‘_DEPRECATED_DOUBLE_BORDER’, ‘_DEPRECATED_FRAME’, ‘_DEPRECATED_HEADER’, ‘_DEPRECATED_MARKDOWN’, ‘_DEPRECATED_MSWORD_FRIENDLY’, ‘_DEPRECATED_NONE’, ‘_DEPRECATED_ORGMODE’, ‘_DEPRECATED_PLAIN_COLUMNS’, ‘_DEPRECATED_RANDOM’, ‘_DEPRECATED_SINGLE_BORDER’, ‘HRuleStyle’, ‘PrettyTable’, ‘RowType’, ‘TableHandler’, ‘TableStyle’, ‘VRuleStyle’, ‘_warn_deprecation’, ‘from_csv’, ‘from_db_cursor’, ‘from_html’, ‘from_html_one’, ‘from_json’, ‘all’, ‘getattr’])

1 Like