I am getting this error on fly server:
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] ERROR: Exception in ASGI application
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] Traceback (most recent call last):
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] result = await app( # type: ignore[func-returns-value]
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return await self.app(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await super().__call__(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await self.middleware_stack(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] raise exc
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await self.app(scope, receive, _send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] raise exc
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await app(scope, receive, sender)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/routing.py", line 756, in __call__
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await self.middleware_stack(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await route.handle(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await self.app(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/routing.py", line 77, in app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await wrap_app_handling_exceptions(app, request)(scope, receive, send)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] raise exc
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] await app(scope, receive, sender)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/routing.py", line 72, in app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] response = await func(request)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] raw_response = await run_endpoint_function(
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return await run_in_threadpool(dependant.call, **values)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return await anyio.to_thread.run_sync(func, *args)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return await get_async_backend().run_sync_in_worker_thread(
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return await future
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 859, in run
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] result = context.run(func, *args)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/workspace/main.py", line 31, in process_user
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] scored_df, post_metrics_df, pricing_df = process_user_data(user_id, social)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/workspace/data_processing.py", line 254, in process_user_data
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] append_to_postgres(impact_socials_df, 'user_impact_socials', DB_URL) #user_impact_socials
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/workspace/database.py", line 7, in append_to_postgres
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] df.to_sql(table_name, engine, if_exists='append', index=False)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/pandas/util/_decorators.py", line 333, in wrapper
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return func(*args, **kwargs)
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/pandas/core/generic.py", line 3087, in to_sql
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] return sql.to_sql(
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/pandas/io/sql.py", line 841, in to_sql
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] with pandasSQL_builder(con, schema=schema, need_transaction=True) as pandas_sql:
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_pip-install/packages/lib/python3.10/site-packages/pandas/io/sql.py", line 895, in pandasSQL_builder
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] import sqlite3
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_cpython/cpython/lib/python3.10/sqlite3/__init__.py", line 57, in <module>
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] from sqlite3.dbapi2 import *
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] File "/layers/paketo-buildpacks_cpython/cpython/lib/python3.10/sqlite3/dbapi2.py", line 27, in <module>
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] from _sqlite3 import *
2024-08-15T19:49:54.077 app[d890ed7b764418] lhr [info] ImportError: libsqlite3.so.0: cannot open shared object file: No such file or directory
This is the main error here:
ImportError: libsqlite3.so.0: cannot open shared object file: No such file or directory from _sqlite3 import *
This is my database file:
import pandas as pd
from sqlalchemy import create_engine
import logging
def append_to_postgres(df, table_name, db_url):
engine = create_engine(db_url)
df.to_sql(table_name, engine, if_exists='append', index=False)
logging.info(f'Appended dataframe to {table_name} table')
def upload_dataframe_to_postgres(df, table_name, db_url):
try:
engine = create_engine(db_url)
df.to_sql(table_name, engine, if_exists='append', index=False)
logging.info(f"Uploaded dataframe to {table_name} table")
except Exception as e:
logging.error(f"Failed to upload dataframe to {table_name} table: {str(e)}")
It works on my docker environment locally
Dockerfile:
FROM python:3.11-bullseye
RUN apt-get update && apt-get install -y \
libsqlite3-dev \
libsqlite3-0 \
sqlite3 \
build-essential \
&& apt-get clean
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
ENV PORT=8080
# Make port 8080 available to the world outside this container
EXPOSE 8080
# Run flask app
# Run the FastAPI application using uvicorn server
CMD uvicorn main:app --host 0.0.0.0 --port $PORT
I have tried everything but I keep getting this error. I know it is coming from sqlalchemy and panda packages.
I need help.