App Platform: API works perfect in prod but doesn't work

Posted October 16, 2020 898 views
PythonAPIPython FrameworksFlask

Hey all,

I’m writing an API and my API works completely on my machine, but then when I deploy it to DO’s App platform the auth and login functionality works but my schedulecontent/ resource breaks complaining:

phlik-it | 2020-10-15 20:00:12 - - [16/Oct/2020 01:00:12] "GET /schedulecontent HTTP/1.1" 308 -
phlik-it | 2020-10-15 20:00:12 [2020-10-16 01:00:12,517] ERROR in app: Exception on /schedulecontent/ [GET]
phlik-it | 2020-10-15 20:00:12 Traceback (most recent call last):
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask/", line 1950, in full_dispatch_request
phlik-it | 2020-10-15 20:00:12     rv = self.dispatch_request()
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask/", line 1936, in dispatch_request
phlik-it | 2020-10-15 20:00:12     return self.view_functions[rule.endpoint](**req.view_args)
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask_restful/", line 468, in wrapper
phlik-it | 2020-10-15 20:00:12     resp = resource(*args, **kwargs)
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask/", line 89, in view
phlik-it | 2020-10-15 20:00:12     return self.dispatch_request(*args, **kwargs)
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask_restful/", line 583, in dispatch_request
phlik-it | 2020-10-15 20:00:12     resp = meth(*args, **kwargs)
phlik-it | 2020-10-15 20:00:12   File "/usr/local/lib/python3.7/site-packages/flask_jwt/", line 177, in decorator
phlik-it | 2020-10-15 20:00:12     return fn(*args, **kwargs)
phlik-it | 2020-10-15 20:00:12   File "/app/Resources/", line 54, in get
phlik-it | 2020-10-15 20:00:12     cursor.execute(query)
phlik-it | 2020-10-15 20:00:12 sqlite3.OperationalError: no such column: None

and this makes no sense because everything is working just fine locally so there’s nothing for me to troubleshoot?

Any help or guidance on troubleshooting something like this would be MUCH appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

It looks like you might be trying to use SQLite as your database and bundling it with your app. I can’t dig in further to confirm without more information, but you will want to avoid using SQLite and make use of MySQL or Postgres via our DBaaS product. Services deployed on app platform need to be ephemeral as any data you write to disk will be lost the next time you deploy or maintenance needs to occur. It’s possible that the location where your database is supposed to exist on disk is not accessible and therefore unreachable. If I am mistaken and you are not utilizing SQLite please let me know.

  • Yeah I am using a built-in DB with the API while I fill it out with more resources, is there a decent/cost-effective option for keeping my API online using a regular database? the function in question are below.

        # Create
        def post(self):
            data = self.parser.parse_args()
            # Connect to the application database.
            connection = sqlite3.connect('data.db')
            cursor = connection.cursor()
            query = "INSERT INTO {table} VALUES (NULL,?,?,?,?,?)".format(table=self.TABLE_NAME)
            cursor.execute(query, (data['date'], data['post_date'], data['campaign'],data['targeted_platforms'], data['content']))    
            post_id = cursor.lastrowid
            # Save our changes...
            return {"Message":"Your Post (ID: {post_id}) has been successfully scheduled".format(post_id=post_id)}, 200
        # Read
        def get(self):
            connection = sqlite3.connect('data.db')
            cursor = connection.cursor()
            data = self.parser.parse_args()
            query = "SELECT * FROM ContentSchedule WHERE id={row}".format(row=data['scheduledContentID'])
            result = cursor.fetchall()
            return result[0]

Hello! This error appears to be coming from an SQLite database. SQLite is generally recommended only for development and importantly WILL see data loss in a containerized environment like the App Platform. Local disk storage on the App Platform is ephemeral. Anything written to local disk (including the SQLite DB) will disappear when the container is replaced or restarted. For persistent storage we commend using a database like the App Platform’s dev database or DigitalOcean managed databases.

  • hey just to kinda set my expectations. is this a community for discussing code/projects/ etc or is this more just DO services and issues with them?

    • This is definitely a community. You might hear back from another DigitalOcean user before you hear from us, the staff. All of the teams at the company are watching the posts on the community. We want to respond as soon as we can, and make an effort to do so. Feel free to ask anything and everything on this site.