Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Server Error viewing Kobo token. #2235

Open
ggreen88 opened this issue Dec 22, 2021 · 9 comments
Open

Internal Server Error viewing Kobo token. #2235

ggreen88 opened this issue Dec 22, 2021 · 9 comments
Labels

Comments

@ggreen88
Copy link

ggreen88 commented Dec 22, 2021

Describe the bug/problem
When I try and view my kobo token, I get an Internal Server Error. I have included the browser response and calibre-web.log

To Reproduce
Steps to reproduce the behavior:

  1. Goto 'Edit User' page
  2. Click on "Create/View" button under Kobo Sync Token
  3. "Generate Kobo Auth URL dialog pops up with '...'
  4. Nothing happens, and if I look in the developer tools, an internal server error response is passed back

Further Details
Did some further research, and believe the issue is related to the code in kobo_auth.py, starting at line 153:


        books = calibre_db.session.query(db.Books).join(db.Data).all()

        for book in books:
            formats = [data.format for data in book.data]
            if not 'KEPUB' in formats and config.config_kepubifypath and 'EPUB' in formats:
                helper.convert_book_format(book.id, config.config_calibre_dir, 'EPUB', 'KEPUB', current_user.name)


It appears this section is trying to go through all my books and convert epubs to kepubs. I currently have a problem with the converter which errors out. Not a big deal, I can convert books elsewhere. Also, have a large library (1.5k books or so), so I have it so I only sync for a shelf, not the whole library, but the code above doesn't factor that in. Would prefer that the library doesn't automatically try and convert all my books.

Browser Response

Click here!
Calibre-Web | HTTP Error (Internal Server Error)          

Calibre-Web
===========

Internal Server Error
=====================

### 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 1802, in \_execute\_context
self.dialect.do\_execute(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/default.py", line 719, in do\_execute
cursor.execute(statement, parameters)
sqlite3.InterfaceError: Cursor needed to be reset because of commit/rollback and can no longer be fetched from.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi\_app
response = self.full\_dispatch\_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full\_dispatch\_request
rv = self.handle\_user\_exception(e)
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full\_dispatch\_request
rv = self.dispatch\_request()
File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch\_request
return self.ensure\_sync(self.view\_functions\[rule.endpoint\])(\*\*req.view\_args)
File "/usr/local/lib/python3.8/dist-packages/flask\_login/utils.py", line 272, in decorated\_view
return func(\*args, \*\*kwargs)
File "/app/calibre-web/cps/kobo\_auth.py", line 158, in generate\_auth\_token
helper.convert\_book\_format(book.id, config.config\_calibre\_dir, 'EPUB', 'KEPUB', current\_user.name)
File "/app/calibre-web/cps/helper.py", line 77, in convert\_book\_format
data = calibre\_db.get\_book\_format(book.id, old\_book\_format)
File "/app/calibre-web/cps/db.py", line 612, in get\_book\_format
return self.session.query(Data).filter(Data.book == book\_id).filter(Data.format == file\_format).first()
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/query.py", line 2810, in first
return self.limit(1).\_iter().first()
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/query.py", line 2894, in \_iter
result = self.session.execute(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/session.py", line 1689, in execute
result = conn.\_execute\_20(statement, params or {}, execution\_options)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 1614, in \_execute\_20
return meth(self, args\_10style, kwargs\_10style, execution\_options)
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/sql/elements.py", line 325, in \_execute\_on\_connection
return connection.\_execute\_clauseelement(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 1481, in \_execute\_clauseelement
ret = self.\_execute\_context(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 1845, in \_execute\_context
self.\_handle\_dbapi\_exception(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 2026, in \_handle\_dbapi\_exception
util.raise\_(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/compat.py", line 207, in raise\_
raise exception
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 1802, in \_execute\_context
self.dialect.do\_execute(
File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/default.py", line 719, in do\_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Cursor needed to be reset because of commit/rollback and can no longer be fetched from.
\[SQL: SELECT calibre.data.id AS calibre\_data\_id, calibre.data.book AS calibre\_data\_book, calibre.data.format AS calibre\_data\_format, calibre.data.uncompressed\_size AS calibre\_data\_uncompressed\_size, calibre.data.name AS calibre\_data\_name
FROM calibre.data
WHERE calibre.data.book = ? AND calibre.data.format = ?
LIMIT ? OFFSET ?\]
\[parameters: (268, 'EPUB', 1, 0)\]

(Background on this error at: https://sqlalche.me/e/14/rvf5)

Please report this issue with all related information: [Create Issue](https://github.com/janeczku/calibre-web/issues/new?assignees=&labels=&template=bug_report.md&title=)

[Return to Home](/ "Return to Home")`

Logfile

Click here!
[2021-12-22 20:23:42,285]  INFO {cps.tasks.convert:125} Book id 248 - target format of .kepub does not exist. Moving forward with convert.
[2021-12-22 20:23:42,623]  INFO {cps.tasks.convert:164} ebook converter failed with error while converting book
[2021-12-22 20:23:42,625] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,626] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,628] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,631] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,632] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,632] ERROR {cps.services.worker:181} Error creating function
[2021-12-22 20:23:42,637]  INFO {cps.tasks.convert:125} Book id 255 - target format of .kepub does not exist. Moving forward with convert.
[2021-12-22 20:23:48,042] ERROR {cps:1457} Exception on /kobo_auth/generate_auth_token/4 [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 977, in fetchall
    rows = dbapi_cursor.fetchall()
sqlite3.InterfaceError: Cursor needed to be reset because of commit/rollback and can no longer be fetched from.

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/dist-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.8/dist-packages/flask_login/utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "/app/calibre-web/cps/kobo_auth.py", line 158, in generate_auth_token
    helper.convert_book_format(book.id, config.config_calibre_dir, 'EPUB', 'KEPUB', current_user.name)
  File "/app/calibre-web/cps/helper.py", line 76, in convert_book_format
    book = calibre_db.get_book(book_id)
  File "/app/calibre-web/cps/db.py", line 602, in get_book
    return self.session.query(Books).filter(Books.id == book_id).first()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/query.py", line 2810, in first
    return self.limit(1)._iter().first()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 1383, in first
    return self._only_one_row(
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 558, in _only_one_row
    row = onerow(hard_close=True)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 1271, in _fetchone_impl
    return self._real_result._fetchone_impl(hard_close=hard_close)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 1674, in _fetchone_impl
    row = next(self.iterator, _NO_ROW)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/loading.py", line 147, in chunks
    fetch = cursor._raw_all_rows()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 391, in _raw_all_rows
    rows = self._fetchall_impl()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 1803, in _fetchall_impl
    return self.cursor_strategy.fetchall(self, self.cursor)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 981, in fetchall
    self.handle_exception(result, dbapi_cursor, e)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 941, in handle_exception
    result.connection._handle_dbapi_exception(
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/base.py", line 2026, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 977, in fetchall
    rows = dbapi_cursor.fetchall()
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Cursor needed to be reset because of commit/rollback and can no longer be fetched from.
(Background on this error at: https://sqlalche.me/e/14/rvf5)
[2021-12-22 20:23:48,049] ERROR {cps.tasks.convert:152} Database error: (sqlite3.DatabaseError) another row available
(Background on this error at: https://sqlalche.me/e/14/4xp6)

Expected behavior
That the application doesn't automatically try and convert my books to kepubs when I Create/View my kobo sync token.

System Info

Component Information
Host Docker v20.10.7
Program Library Installed Version
Platform Linux 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 x86_64
Python 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
Calibre_Web 0.6.14 - 4da64ce - 2021-10-31T11:31:53+01:00
WebServer Gevent 21.8.0
Flask 2.0.2
Flask_Login 0.5.0
Flask_Principal 0.4.0
Flask_WTF 0.15.1
Werkzeug 2.0.2
Babel 2.9.1
Jinja2 3.0.3
Requests 2.24.0
SqlAlchemy 1.4.27
pySqlite 2.6.0
SQLite 3.31.1
iso639 0.4.5
pytz 2021.3
Unidecode installed
Scholarly installed
Flask_SimpleLDAP installed
python_LDAP 3.3.1
Goodreads installed
jsonschema 3.2.0
flask_dance 5.0.0
greenlet 1.1.2
Image Magick ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
PyPdf v1.0.3
lxml v4.6.4.0
Wand 0.6.7
Comic_API 2.2.0
ebook converter ebook-convert (calibre 5.34.0)
unrar UNRAR 5.61 beta 1 freeware Copyright (c) 1993-2018 Alexander Roshal
kepubify kepubify v4.0.2
@shad-lp
Copy link

shad-lp commented May 8, 2022

I'm in the same boat.
I'll add that I tried with and without Authelia with the very same result, so that's not related.

@nstetter
Copy link

Just stumbled upon this too

@mfournierca
Copy link

I have also encountered this issue.

@joost12345
Copy link

Same issue here..

@n0nuser
Copy link

n0nuser commented Sep 23, 2022

Same here!

Error editing book: (sqlite3.InterfaceError) Cursor needed to be reset because of commit/rollback and can no longer be fetched from. [SQL: SELECT tags.id AS tags_id, tags.name AS tags_name FROM tags WHERE tags.name = ? LIMIT ? OFFSET ?] [parameters: ('Fiction', 1, 0)] (Background on this error at: https://sqlalche.me/e/14/rvf5)

In my case I was just editing the metadata of a book.

@MrHappy
Copy link

MrHappy commented Oct 9, 2022

Same issue here, but it seems to work when I do not use a reverse proxy...
That no problem when I want to sync my Kobo at home, but when I'm outside the house I will not be able to sync my Kobo...

Edit:
I was wrong... It still errors.... It seems like hit and miss...

@shad-lp
Copy link

shad-lp commented Nov 13, 2022

@MrHappy I can confirm it's not working with or without a reverse proxy.

@pnodet
Copy link

pnodet commented Dec 31, 2022

I just ran into the same problem with a large library. I'm really not a big fan of the idea of formatting all books into kepub.

I was trying to generate a token and had no idea that it would try to convert all my books. I have about 14,000 books and calibre-web runs on an old computer at home. The app crashed trying to format all the books from pub to kepub. Visually, nothing happens with just ... instead of the token. Had to login via ssh to restart the container.

I used my laptop to convert the book into Calibre and it works fine now, but I would have liked to have a warning and/or an option to avoid this.

@teetui
Copy link

teetui commented Jul 4, 2023

@pnxdxt

I just ran into the same problem with a large library. I'm really not a big fan of the idea of formatting all books into kepub.

I have about 2100 epub files, and I wish I could get past this problem. All I can see is "..." when generating a Kobo Auth URL no matter how long I wait. I don't know what's happening. It was working previously until I added a largish collection of books.

It would be nice if the books could be converted to kepub on the fly instead of all at once like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants