Calibre-web: sqlalchemy.exc.OperationalError at startup on QNAP-NAS

Created on 31 Mar 2018  路  19Comments  路  Source: janeczku/calibre-web

I want to manage my ebooks via this and have a QNAP NAS, can I install this on it somehow ?

question

All 19 comments

This question is very unspecific.
Do you have shell access (via ssh?).
Clone the repro to a folder.
Install python if not already done, install dependencies like described in the readme.
Start the program.

Same question. _m going to try using linux station I guess.._

Please describe the exact problem, otherwise I will close the issue.

I will later (currently not on pc) post the Error I am getting while trying to install this.

@OzzieIsaacs This is the error I am getting when trying to run python cps.py :

Successfully built Flask-Babel Flask-Login Flask-Principal iso-639 PyPDF2 SQLAlchemy tornado blinker itsdangerous MarkupSafe Installing collected packages: pytz, Babel, itsdangerous, MarkupSafe, Jinja2, Werkzeug, click, Flask, Flask-Babel, Flask-Login, blinker, Flask-Principal, iso-639, PyPDF2, idna, urllib3, certifi, chardet, requests, SQLAlchemy, futures, six, singledispatch, backports-abc, tornado, Wand, unidecode Successfully installed Babel-2.5.3 Flask-0.12.2 Flask-Babel-0.11.1 Flask-Login-0.4.1 Flask-Principal-0.4.0 Jinja2-2.10 MarkupSafe-1.0 PyPDF2-1.26.0 SQLAlchemy-1.2.6 Wand-0.4.4 Werkzeug-0.14.1 backports-abc-0.5 blinker-1.4 certifi-2018.1.18 chardet-3.0.4 click-6.7 futures-3.2.0 idna-2.6 iso-639-0.4.5 itsdangerous-0.24 pytz-2018.3 requests-2.18.4 singledispatch-3.4.0.3 six-1.11.0 tornado-5.0.1 unidecode-1.0.22 urllib3-1.22

[/share/CACHEDEV1_DATA/Python] # python cps.py
Traceback (most recent call last):
File "cps.py", line 13, in
from cps import web
File "/share/CACHEDEV1_DATA/Python/cps/web.py", line 36, in
import ub
File "/share/CACHEDEV1_DATA/Python/cps/ub.py", line 732, in
Base.metadata.create_all(engine)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/schema.py", line 4004, in create_all
tables=tables)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1940, in _run_visitor
conn._run_visitor(visitorcallable, element, *kwargs)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1549, in _run_visitor
*
kwargs).traverse_single(element)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/visitors.py", line 121, in traverse_single
return meth(obj, *kw)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/ddl.py", line 757, in visit_metadata
_is_metadata_operation=True)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/visitors.py", line 121, in traverse_single
return meth(obj, *
kw)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/ddl.py", line 791, in visit_table
include_foreign_key_constraints=include_foreign_key_constraints
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 948, in execute
return meth(self, multiparams, params)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1009, in _execute_ddl
compiled
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1200, in _execute_context
context)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
exc_info
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/base.py", line 1193, in _execute_context
context)
File "/share/CACHEDEV1_DATA/Python/vendor/sqlalchemy/engine/default.py", line 507, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near ""NOCASE"": syntax error [SQL: u'\nCREATE TABLE bookmark (\n\tid INTEGER NOT NULL, \n\tuser_id INTEGER, \n\tbook_id INTEGER, \n\tformat VARCHAR COLLATE "NOCASE", \n\tbookmark_key VARCHAR, \n\tPRIMARY KEY (id), \n\tFOREIGN KEY(user_id) REFERENCES user (id)\n)\n\n'] (Background on this error at: http://sqlalche.me/e/e3q8)

It has something to do with the sqlite database (storage for parameters of calibre-web)
Could you please go to the "vendor" directory and start a python console by typing: python.
And than enter the following sequence:

from sqlalchemy import *
engine = create_engine('sqlite:////share/CACHEDEV1_DATA/Python/test.db', echo=False)
engine.dialect.dbapi.version
engine.dialect.dbapi.sqlite_version

Please post the output of this and please also the python version (should show up after starting the python command)
I assume that the user running the python command has write permissions in the folder where cps.py is located?

This is the output:

`[/share/CACHEDEV1_DATA/Python/vendor] # python
Python 2.7.5 (default, Mar 31 2018, 03:16:11)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from sqlalchemy import *
engine = create_engine('sqlite:////share/CACHEDEV1_DATA/Python/test.db', echo=False)
engine.dialect.dbapi.version
'2.6.0'
engine.dialect.dbapi.sqlite_version
'3.4.1'
`

Yes it has the write permissions. Should be the admin user (Any way to double check this again? Just to be 100% sure) (Sorry for the questions. I am quite new to python)

Your sqlite version is rather old, but I just changed the changelog, nothing relevant seems to be changed. I believe it's not the write permission, its a problem with the database.
Could you please go to cps/ub.py and change line 250 from:
format = Column(String(collation='NOCASE'))
to:
format = Column(String)
(Be carefull with the tabs and spaces beginning of the line, they are important).
Try to start the program afterwards. It hopefully should work then. (Sideeffect: Bookmarks in the online-reader maybe could not be correct set and found again)

Thank you for answering. Just did the change in the file. Now I get the following error:

[/share/CACHEDEV1_DATA/Python] # python cps.py
Traceback (most recent call last):
File "cps.py", line 13, in
from cps import web
File "/share/CACHEDEV1_DATA/Python/cps/web.py", line 36, in
import ub
File "/share/CACHEDEV1_DATA/Python/cps/ub.py", line 744, in
config = Config()
File "/share/CACHEDEV1_DATA/Python/cps/ub.py", line 334, in __init__
self.loadSettings()
File "/share/CACHEDEV1_DATA/Python/cps/ub.py", line 339, in loadSettings
self.config_calibre_dir = data.config_calibre_dir
AttributeError: 'NoneType' object has no attribute 'config_calibre_dir'

Could you please try to delete the app.db file in the ../Python/ folder and restart it again (it鈥榮 still database issue, now no data can鈥榯 read from database). Other idea would be: from the qnap website I saw you can install python3. Would this be an option for you?

Just deleted the file and run python cps.py again:

Now I get this error:
[/share/CACHEDEV1_DATA/Python] # python cps.py
Traceback (most recent call last):
File "cps.py", line 13, in
from cps import web
File "/share/CACHEDEV1_DATA/Python/cps/web.py", line 38, in
import helper
File "/share/CACHEDEV1_DATA/Python/cps/helper.py", line 4, in
import db
File "/share/CACHEDEV1_DATA/Python/cps/db.py", line 9, in
import ast
ImportError: No module named ast

Regarding python3, I would not install python 3 right now, because it is very unstable on qnap system according to QNAP staff. And QNAP staff adviced to use python2. So if possible I would like to keep the current python version.

Very strange, but we are getting closer. Please go into the ../Python/ folder and start:
pip install --target vendor ast.
After successfully installing this, try to restart. If more ImportErrors appear, please redo the procedure above with the missing module name (in this case it was ast).

It gets even more strange now. I installed ast but it still says it is missing.

Collecting ast
Downloading AST-0.0.2-py2-none-any.whl
Installing collected packages: ast
Successfully installed ast-0.0.2
[/share/CACHEDEV1_DATA/Python] # python cps.py
Traceback (most recent call last):
File "cps.py", line 13, in
from cps import web
File "/share/CACHEDEV1_DATA/Python/cps/web.py", line 38, in
import helper
File "/share/CACHEDEV1_DATA/Python/cps/helper.py", line 4, in
import db
File "/share/CACHEDEV1_DATA/Python/cps/db.py", line 9, in
import ast
ImportError: No module named ast


Maybe this is an better approach to try:

Completly new question could I use this: https://www.qnap.com/solution/container_station/en/ and then use this https://hub.docker.com/r/technosoft2000/calibre-web/ ?

I mean that docker image should have everything needed already inside right ?

Thank you by the way for beeing so patient with me!

The ast module is the wrong one (didn't check it). It looks like the ast support has to be compiled into python or it is not available. Let's give it 2 last tries:
start a python console by typing: python
And than enter the following:
import _ast
If no Traceback output comes, please download the ast.py file from:
https://svn.python.org/projects/python/trunk/Lib/ast.py
and place it in the vendor folder, and try another start.
If error occurs please change line 9 from cps/db.py from:
import ast
to:
#import ast
and line 298 in the same file from:
display_dict = ast.literal_eval(self.display)
to
display_dict = dict()
Than keep fingers crossed, and try to start it again.
If this works, I program a workaround for this one.

Your last question: As far as I understood it, the docker containers are plattform dependend (x86 container will only run on x86 machine, as this post implies:
https://forums.docker.com/t/docker-image-compatibility-between-x86-and-arm/7149/5).
I assume that there is a big chance of having an ARM based machine, and than it won't work?
One the other hand there is a manual describing how to set it up for synology.
Best would be to ask @Technosoft2000 about the compability.

I have got it running now using the docker version and can access it now.

Now this leaves me only with one question how can I apply this: https://github.com/janeczku/calibre-web/issues/454 to my calibre web docker version ?

(Regarding the solution you proposed, i will try that one on an old qnap nas I have and then report back to you regarding it)

You have to wait for technosoft to integrate it in the docker container, sorry.

Hi @gelsas,

I'll check how I can integrate #454 into the docker image - I've created an issue at my repo https://github.com/Technosoft2000/docker-calibre-web/issues/26

Had the same problem, i solved it by login to my root account and installing the calibre and calibre web using the root account., i think it access right to calibre files

Hi @gelsas,

in the latest release v1.1.11 of my docker image #454 caliBlur! CSS is integrated and can be directly changed over the Web Interface of Calibre-Web

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  7Comments

jvimedia picture jvimedia  路  9Comments

InsOpDe picture InsOpDe  路  4Comments

enigmaticlilit picture enigmaticlilit  路  8Comments

christophwolff picture christophwolff  路  6Comments