academy
academy copied to clipboard
API-oedialect `to_sql` bug
I was testing the oedialect API, and I tried to run the following script: https://github.com/OpenEnergyPlatform/examples/blob/master/api/OEP-oedialect_upload_from_csv.ipynb
Unfortunately, I encountered an error which I cannot be able to understand.
For the code in line in[9]
(insert data into table)
oedialect (0.0.5.dev0)
Error:
---------------------------------------------------------------------------
ConnectionException Traceback (most recent call last)
<ipython-input-9-241a71346142> in <module>()
2 session = Session()
3 try:
----> 4 example_df.to_sql(table_name, conn, schema_name, if_exists='replace')
5 print('Inserted to ' + table_name)
6 except Exception as e:
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in to_sql(self, name, con, schema, if_exists, index, index_label, chunksize, dtype)
2128 sql.to_sql(self, name, con, schema=schema, if_exists=if_exists,
2129 index=index, index_label=index_label, chunksize=chunksize,
-> 2130 dtype=dtype)
2131
2132 def to_pickle(self, path, compression='infer',
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in to_sql(frame, name, con, schema, if_exists, index, index_label, chunksize, dtype)
448 pandas_sql.to_sql(frame, name, if_exists=if_exists, index=index,
449 index_label=index_label, schema=schema,
--> 450 chunksize=chunksize, dtype=dtype)
451
452
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in to_sql(self, frame, name, if_exists, index, index_label, schema, chunksize, dtype)
1124 if_exists=if_exists, index_label=index_label,
1125 schema=schema, dtype=dtype)
-> 1126 table.create()
1127 table.insert(chunksize)
1128 if (not name.isdigit() and not name.islower()):
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in create(self)
563 raise ValueError("Table '%s' already exists." % self.name)
564 elif self.if_exists == 'replace':
--> 565 self.pd_sql.drop_table(self.name, self.schema)
566 self._execute_create()
567 elif self.if_exists == 'append':
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in drop_table(self, table_name, schema)
1174 if self.has_table(table_name, schema):
1175 self.meta.reflect(only=[table_name], schema=schema)
-> 1176 self.get_table(table_name, schema).drop()
1177 self.meta.clear()
1178
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/sql/schema.py in drop(self, bind, checkfirst)
830 if bind is None:
831 bind = _bind_or_error(self)
--> 832 bind._run_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst)
833
834 def tometadata(
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _run_visitor(self, visitorcallable, element, **kwargs)
1597
1598 def _run_visitor(self, visitorcallable, element, **kwargs):
-> 1599 visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
1600
1601
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/sql/visitors.py in traverse_single(self, obj, **kw)
128 meth = getattr(v, "visit_%s" % obj.__visit_name__, None)
129 if meth:
--> 130 return meth(obj, **kw)
131
132 def iterate(self, obj):
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py in visit_table(self, table, drop_ok, _is_metadata_operation)
998 )
999
-> 1000 self.connection.execute(DropTable(table))
1001
1002 # traverse client side defaults which may refer to server-side
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, object_, *multiparams, **params)
978 raise exc.ObjectNotExecutableError(object_)
979 else:
--> 980 return meth(self, multiparams, params)
981
982 def _execute_function(self, func, multiparams, params):
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py in _execute_on_connection(self, connection, multiparams, params)
70
71 def _execute_on_connection(self, connection, multiparams, params):
---> 72 return connection._execute_ddl(self, multiparams, params)
73
74 def execute(self, bind=None, target=None):
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_ddl(self, ddl, multiparams, params)
1040 compiled,
1041 None,
-> 1042 compiled,
1043 )
1044 if self._has_events or self.engine._has_events:
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1238 except BaseException as e:
1239 self._handle_dbapi_exception(
-> 1240 e, statement, parameters, cursor, context
1241 )
1242
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
1458 util.raise_from_cause(sqlalchemy_exception, exc_info)
1459 else:
-> 1460 util.reraise(*exc_info)
1461
1462 finally:
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
275 if value.__traceback__ is not tb:
276 raise value.with_traceback(tb)
--> 277 raise value
278
279
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1234 if not evt_handled:
1235 self.dialect.do_execute(
-> 1236 cursor, statement, parameters, context
1237 )
1238 except BaseException as e:
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
534
535 def do_execute(self, cursor, statement, parameters, context=None):
--> 536 cursor.execute(statement, parameters)
537
538 def do_execute_no_params(self, cursor, statement, context=None):
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/oedialect/engine.py in execute(self, query_obj, params)
308 command = query.pop('command')
309 return self.__execute_by_post(command, query,
--> 310 requires_connection_id=requires_connection_id)
311
312 def executemany(self, query, params=None):
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/oedialect/engine.py in __execute_by_post(self, command, query, requires_connection_id)
325
326 response = self.__connection.post(command, query, cursor_id=self.__id,
--> 327 requires_connection_id=requires_connection_id)
328
329 if 'content' in response:
/home/local/RL-INSTITUT/okan.akca/.local/lib/python3.6/site-packages/oedialect/engine.py in post(self, suffix, query, cursor_id, requires_connection_id)
225
226 if 400 <= ans.status_code < 600:
--> 227 raise ConnectionException(json_response['reason'] if 'reason' in json_response else 'No reason returned')
228
229 return json_response
ConnectionException: No reason returned