"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.0.1\u001B[0m\r\n",
"\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpython3.11 -m pip install --upgrade pip\u001B[0m\r\n"
"query = 'SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2'\n",
"query = 'SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2' # change this!\n",
"df = pd.read_sql(query, conn)\n",
"print(\"Column names in the DataFrame:\", df.columns)\n"
]
"print(\"Column names in the DataFrame:\", df.columns)"
],
"id": "b9fd614aafe049e",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/jm/rgjqkd2s5j5d309wnmpsvddr0000gn/T/ipykernel_75159/1256295774.py:3: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.\n",
" df = pd.read_sql(query, conn)\n",
"Failed to execute query.\n",
"Traceback (most recent call last):\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/pyathena/common.py\", line 586, in _execute\n",
" query_id = retry_api_call(\n",
" ^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/pyathena/util.py\", line 84, in retry_api_call\n",
" return retry(func, *args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py\", line 477, in __call__\n",
" do = self.iter(retry_state=retry_state)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py\", line 378, in iter\n",
" result = action(retry_state)\n",
" ^^^^^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py\", line 400, in <lambda>\n",
" File \"/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py\", line 449, in result\n",
" return self.__get_result()\n",
" ^^^^^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py\", line 401, in __get_result\n",
" raise self._exception\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py\", line 480, in __call__\n",
" result = fn(*args, **kwargs)\n",
" ^^^^^^^^^^^^^^^^^^^\n",
" File \"/opt/homebrew/lib/python3.11/site-packages/botocore/client.py\", line 570, in _api_call\n",
"botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.\n"
]
},
{
"ename": "DatabaseError",
"evalue": "Execution failed on sql: SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2\nAn error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.\nunable to rollback",
"File \u001B[0;32m/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py:401\u001B[0m, in \u001B[0;36mFuture.__get_result\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 400\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 401\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_exception\n\u001B[1;32m 402\u001B[0m \u001B[38;5;28;01mfinally\u001B[39;00m:\n\u001B[1;32m 403\u001B[0m \u001B[38;5;66;03m# Break a reference cycle with the exception in self._exception\u001B[39;00m\n",
"File \u001B[0;32m/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py:480\u001B[0m, in \u001B[0;36mRetrying.__call__\u001B[0;34m(self, fn, *args, **kwargs)\u001B[0m\n\u001B[1;32m 479\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 480\u001B[0m result \u001B[38;5;241m=\u001B[39m \u001B[43mfn\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 481\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mBaseException\u001B[39;00m: \u001B[38;5;66;03m# noqa: B902\u001B[39;00m\n",
"File \u001B[0;32m/opt/homebrew/lib/python3.11/site-packages/botocore/client.py:570\u001B[0m, in \u001B[0;36mClientCreator._create_api_method.<locals>._api_call\u001B[0;34m(self, *args, **kwargs)\u001B[0m\n\u001B[1;32m 569\u001B[0m \u001B[38;5;66;03m# The \"self\" in this scope is referring to the BaseClient.\u001B[39;00m\n\u001B[0;32m--> 570\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_make_api_call\u001B[49m\u001B[43m(\u001B[49m\u001B[43moperation_name\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n",
"\u001B[0;31mClientError\u001B[0m: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001B[0;31mDatabaseError\u001B[0m: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.",
"\nDuring handling of the above exception, another exception occurred:\n",
"File \u001B[0;32m/opt/homebrew/lib/python3.11/site-packages/pandas/io/sql.py:2271\u001B[0m, in \u001B[0;36mSQLiteDatabase.execute\u001B[0;34m(self, sql, params)\u001B[0m\n\u001B[1;32m 2267\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mException\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m inner_exc: \u001B[38;5;66;03m# pragma: no cover\u001B[39;00m\n\u001B[1;32m 2268\u001B[0m ex \u001B[38;5;241m=\u001B[39m DatabaseError(\n\u001B[1;32m 2269\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mExecution failed on sql: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00msql\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;132;01m{\u001B[39;00mexc\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124munable to rollback\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 2270\u001B[0m )\n\u001B[0;32m-> 2271\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m ex \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01minner_exc\u001B[39;00m\n\u001B[1;32m 2273\u001B[0m ex \u001B[38;5;241m=\u001B[39m DatabaseError(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mExecution failed on sql \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00msql\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mexc\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 2274\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m ex \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mexc\u001B[39;00m\n",
"\u001B[0;31mDatabaseError\u001B[0m: Execution failed on sql: SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2\nAn error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.\nunable to rollback"
query='SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2'
query='SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2'# change this!
df=pd.read_sql(query,conn)
print("Column names in the DataFrame:",df.columns)
```
%% Output
/var/folders/jm/rgjqkd2s5j5d309wnmpsvddr0000gn/T/ipykernel_75159/1256295774.py:3: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.
df = pd.read_sql(query, conn)
Failed to execute query.
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.11/site-packages/pyathena/common.py", line 586, in _execute
query_id = retry_api_call(
^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/pyathena/util.py", line 84, in retry_api_call
return retry(func, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 477, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 378, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 400, in <lambda>
File "/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 480, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/botocore/client.py", line 570, in _api_call
botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.
File /opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py:449, in Future.result(self, timeout)
448 elif self._state == FINISHED:
--> 449 return self.__get_result()
451 self._condition.wait(timeout)
File /opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
400 try:
--> 401 raise self._exception
402 finally:
403 # Break a reference cycle with the exception in self._exception
File /opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py:480, in Retrying.__call__(self, fn, *args, **kwargs)
479 try:
--> 480 result = fn(*args, **kwargs)
481 except BaseException: # noqa: B902
File /opt/homebrew/lib/python3.11/site-packages/botocore/client.py:570, in ClientCreator._create_api_method.<locals>._api_call(self, *args, **kwargs)
569 # The "self" in this scope is referring to the BaseClient.
ClientError: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.
The above exception was the direct cause of the following exception:
DatabaseError Traceback (most recent call last)
File /opt/homebrew/lib/python3.11/site-packages/pandas/io/sql.py:2262, in SQLiteDatabase.execute(self, sql, params)
DatabaseError: An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.
During handling of the above exception, another exception occurred:
2327 columns = [col_desc[0] for col_desc in cursor.description]
2329 if chunksize is not None:
File /opt/homebrew/lib/python3.11/site-packages/pandas/io/sql.py:2271, in SQLiteDatabase.execute(self, sql, params)
2267 except Exception as inner_exc: # pragma: no cover
2268 ex = DatabaseError(
2269 f"Execution failed on sql: {sql}\n{exc}\nunable to rollback"
2270 )
-> 2271 raise ex from inner_exc
2273 ex = DatabaseError(f"Execution failed on sql '{sql}': {exc}")
2274 raise ex from exc
DatabaseError: Execution failed on sql: SELECT device_id, data.vehicle_CO2 FROM vehicledatabase.lab4data_mylesai2
An error occurred (AccessDeniedException) when calling the StartQueryExecution operation: You are not authorized to perform: athena:StartQueryExecution on the resource. After your AWS administrator or you have updated your permissions, please try again.