Having werkzeug.expectation.BadRequestKeyError(key) and sqlite3.OperationalError: no such table: file errors #75

Closed
opened 2022-12-21 20:35:39 +01:00 by DestroyerAce · 2 comments

Hi and sorry for disturbing you. I am pretty new to self hosting and web server stuff and having the problems I mentioned in title. Thanks.

(env) ubuntu@server ~/0x0 (master)> uwsgi --socket 0.0.0.0:5000 --protocol=http --wsgi-file fhost.py --callable app
*** Starting uWSGI 2.0.21 (64bit) on [Wed Dec 21 19:30:12 2022] ***
compiled with version: 11.3.0 on 19 December 2022 01:16:55
os: Linux-5.15.0-1025-oracle #31-Ubuntu SMP Fri Nov 25 17:03:15 UTC 2022
nodename: server
machine: aarch64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/ubuntu/0x0
detected binary path: /home/ubuntu/0x0/env/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 95671
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3
Python version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xaaaaf74e9290
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xaaaaf74e9290 pid: 16390 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 16390, cores: 1)
[pid: 16390|app: 0|req: 1/1] 127.0.0.1 () {24 vars in 248 bytes} [Wed Dec 21 19:30:16 2022] GET / => generated 2417 bytes in 12 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
[2022-12-21 19:30:18,947] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "fhost.py", line 496, in fhost
    int(request.form["expires"]),
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/werkzeug/datastructures.py", line 375, in __getitem__
    raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "fhost.py", line 505, in fhost
    return store_file(
  File "fhost.py", line 372, in store_file
    sf, isnew = File.store(f, requested_expiration, addr, secret)
  File "fhost.py", line 258, in store
    f = File.query.filter_by(sha256=digest).first()
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2824, in first
    return self.limit(1)._iter().first()
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2916, in _iter
    result = self.session.execute(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1714, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1572, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1943, in _execute_context
    self._handle_dbapi_exception(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception
    util.raise_(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: file
[SQL: SELECT file.id AS file_id, file.sha256 AS file_sha256, file.ext AS file_ext, file.mime AS file_mime, file.addr AS file_addr, file.removed AS file_removed, file.nsfw_score AS file_nsfw_score, file.expiration AS file_expiration, file.mgmt_token AS file_mgmt_token, file.secret AS file_secret, file.last_vscan AS file_last_vscan, file.size AS file_size 
FROM file 
WHERE file.sha256 = ?
 LIMIT ? OFFSET ?]
[parameters: ('a4f0e64b55fe2f53b44a1a464a4f61fe692daa32de5fe6a8ea10b145f4960f07', 1, 0)]
(Background on this error at: https://sqlalche.me/e/14/e3q8)
[pid: 16390|app: 0|req: 2/2] 127.0.0.1 () {28 vars in 356 bytes} [Wed Dec 21 19:30:18 2022] POST / => generated 265 bytes in 12 msecs (HTTP/1.1 500) 2 headers in 99 bytes (1 switches on core 0)
Hi and sorry for disturbing you. I am pretty new to self hosting and web server stuff and having the problems I mentioned in title. Thanks. ``` (env) ubuntu@server ~/0x0 (master)> uwsgi --socket 0.0.0.0:5000 --protocol=http --wsgi-file fhost.py --callable app *** Starting uWSGI 2.0.21 (64bit) on [Wed Dec 21 19:30:12 2022] *** compiled with version: 11.3.0 on 19 December 2022 01:16:55 os: Linux-5.15.0-1025-oracle #31-Ubuntu SMP Fri Nov 25 17:03:15 UTC 2022 nodename: server machine: aarch64 clock source: unix detected number of CPU cores: 4 current working directory: /home/ubuntu/0x0 detected binary path: /home/ubuntu/0x0/env/bin/uwsgi !!! no internal routing support, rebuild with pcre support !!! *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 95671 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3 Python version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0xaaaaf74e9290 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72904 bytes (71 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xaaaaf74e9290 pid: 16390 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 16390, cores: 1) [pid: 16390|app: 0|req: 1/1] 127.0.0.1 () {24 vars in 248 bytes} [Wed Dec 21 19:30:16 2022] GET / => generated 2417 bytes in 12 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0) [2022-12-21 19:30:18,947] ERROR in app: Exception on / [POST] Traceback (most recent call last): File "fhost.py", line 496, in fhost int(request.form["expires"]), File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/werkzeug/datastructures.py", line 375, in __getitem__ raise exceptions.BadRequestKeyError(key) werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context self.dialect.do_execute( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute cursor.execute(statement, parameters) sqlite3.OperationalError: no such table: file The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request rv = self.dispatch_request() File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "fhost.py", line 505, in fhost return store_file( File "fhost.py", line 372, in store_file sf, isnew = File.store(f, requested_expiration, addr, secret) File "fhost.py", line 258, in store f = File.query.filter_by(sha256=digest).first() File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2824, in first return self.limit(1)._iter().first() File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2916, in _iter result = self.session.execute( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1714, in execute result = conn._execute_20(statement, params or {}, execution_options) File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_20 return meth(self, args_10style, kwargs_10style, execution_options) File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection return connection._execute_clauseelement( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1572, in _execute_clauseelement ret = self._execute_context( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1943, in _execute_context self._handle_dbapi_exception( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception util.raise_( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_ raise exception File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context self.dialect.do_execute( File "/home/ubuntu/0x0/env/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: file [SQL: SELECT file.id AS file_id, file.sha256 AS file_sha256, file.ext AS file_ext, file.mime AS file_mime, file.addr AS file_addr, file.removed AS file_removed, file.nsfw_score AS file_nsfw_score, file.expiration AS file_expiration, file.mgmt_token AS file_mgmt_token, file.secret AS file_secret, file.last_vscan AS file_last_vscan, file.size AS file_size FROM file WHERE file.sha256 = ? LIMIT ? OFFSET ?] [parameters: ('a4f0e64b55fe2f53b44a1a464a4f61fe692daa32de5fe6a8ea10b145f4960f07', 1, 0)] (Background on this error at: https://sqlalche.me/e/14/e3q8) [pid: 16390|app: 0|req: 2/2] 127.0.0.1 () {28 vars in 356 bytes} [Wed Dec 21 19:30:18 2022] POST / => generated 265 bytes in 12 msecs (HTTP/1.1 500) 2 headers in 99 bytes (1 switches on core 0) ```
Owner

Make sure you configure the database path in config.py—you may need to use an absolute path there. Once you’ve done that, you need to run FLASK_APP=fhost flask db upgrade to get the database schema set up. It should work after that.

Make sure you configure the database path in `config.py`—you may need to use an absolute path there. Once you’ve done that, you need to run `FLASK_APP=fhost flask db upgrade` to get the database schema set up. It should work after that.
Author

It worked thanks

It worked thanks
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: mia/0x0#75
No description provided.