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

"OSError: [Errno 22] Invalid argument" on Kobo Sync #3037

Closed
sre3 opened this issue Apr 22, 2024 · 3 comments
Closed

"OSError: [Errno 22] Invalid argument" on Kobo Sync #3037

sre3 opened this issue Apr 22, 2024 · 3 comments

Comments

@sre3
Copy link

sre3 commented Apr 22, 2024

Describe the bug/problem

After the kobo sync/integration feature working flawlessly for a few months, it is now completely nonfuntional, with my kobo displaying the message "Sync Failed. Please try again." After briefly debugging connection issues, I checked the log file and was greeted with the traceback below. The included snippet from the logfile is directly after turning up the loglevel to DEBUG.

To Reproduce

Steps to reproduce the behavior:

  1. Attempt to start sync on kobo device (also tried forcing a full resync)

Logfile

[2024-04-21 20:04:37,815]  INFO {cps:177} Starting Calibre Web...
[2024-04-21 20:04:38,469]  WARN {py.warnings:109} /lsiopy/lib/python3.10/site-packages/flask_limiter/extension.py:308: UserWarning: Using the in-memory storage for tracking rate limits as no storage was explicitly specified. This is not recommended for production use. See: https://flask-limiter.readthedocs.io#configuring-a-storage-backend for documentation about configuring the storage backend.
  warnings.warn(
[2024-04-21 20:04:38,879]  INFO {apscheduler.scheduler:181} Scheduler started
[2024-04-21 20:04:38,880]  INFO {apscheduler.scheduler:895} Added job "backup metadata" to job store "default"
[2024-04-21 20:04:38,880]  INFO {apscheduler.scheduler:895} Added job "delete superfluous book covers" to job store "default"
[2024-04-21 20:04:38,881]  INFO {apscheduler.scheduler:895} Added job "generate book covers" to job store "default"
[2024-04-21 20:04:38,881]  INFO {apscheduler.scheduler:895} Added job "end scheduled task" to job store "default"
[2024-04-21 20:04:41,349]  INFO {cps.server:207} Starting Gevent server on [::]:8083
[2024-04-21 20:05:35,806] DEBUG {cps.kobo:1003} Unimplemented Products Request received: https://calibre.sre303.net/kobo/*synctoken*/v1/affiliate (request is forwarded to kobo if configured)
[2024-04-21 20:05:36,053] DEBUG {cps.ub:84} Found stored session: *session*
[2024-04-21 20:05:36,054]  INFO {cps.kobo:1042} Init
[2024-04-21 20:05:36,274] DEBUG {cps.kobo:963} Unimplemented User Request received: https://calibre.sre303.net/kobo/*synctoken*/v1/user/profile (request is forwarded to kobo if configured)
[2024-04-21 20:05:36,606] DEBUG {cps.kobo:1003} Unimplemented Products Request received: https://calibre.sre303.net/kobo/*synctoken*/v1/deals (request is forwarded to kobo if configured)
[2024-04-21 20:05:37,074] DEBUG {cps.ub:84} Found stored session: *session*
[2024-04-21 20:05:37,148]  INFO {cps.kobo:143} Kobo library sync request received.
[2024-04-21 20:05:37,149] DEBUG {cps.kobo:144} SyncToken: 0001-01-01 00:00:00,2024-01-31 03:19:57.932587,0001-01-01 00:00:00,2024-04-21 23:45:44.306769,2024-04-08 05:08:51.140669, *very long sync token here*
[2024-04-21 20:05:37,150] DEBUG {cps.kobo:145} Download link format https://calibre.sre303.net/kobo/*synctoken*/download/%5Bbookid%5D/%5Bbookformat%5D
[2024-04-21 20:05:37,299]  WARN {py.warnings:109} /app/calibre-web/cps/db.py:570: SAWarning: This declarative base already contains a class with the same class name and module name as cps.db.custom_column_7, and will be replaced in the string-lookup table.
  cc_classes[row.id] = type(str('custom_column_' + str(row.id)), (Base,), ccdict)
[2024-04-21 20:05:37,322]  WARN {py.warnings:109} /app/calibre-web/cps/db.py:574: SAWarning: Property Books.custom_column_7 on mapped class Books->books being replaced with new property Books.custom_column_7; the old property will be discarded
  setattr(Books,
[2024-04-21 20:05:37,369] DEBUG {cps.kobo:204} Books to Sync: 1
[2024-04-21 20:05:37,422] ERROR {cps:1414} Exception on /kobo/*synctoken*/v1/library/sync [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/app/calibre-web/cps/kobo_auth.py", line 168, in inner
    return f(*args, **kwargs)
  File "/app/calibre-web/cps/web.py", line 122, in inner
    return f(*args, **kwargs)
  File "/app/calibre-web/cps/kobo.py", line 213, in HandleSyncRequest
    "BookMetadata": get_metadata(book.Books),
  File "/app/calibre-web/cps/kobo.py", line 443, in get_metadata
    if get_epub_layout(book, book_data) == 'pre-paginated':
  File "/app/calibre-web/cps/epub.py", line 55, in get_epub_layout
    txt = epubZip.read('META-INF/container.xml')
  File "/usr/lib/python3.10/zipfile.py", line 1477, in read
    with self.open(name, "r", pwd) as fp:
  File "/usr/lib/python3.10/zipfile.py", line 1532, in open
    fheader = zef_file.read(sizeFileHeader)
  File "/usr/lib/python3.10/zipfile.py", line 746, in read
    self._file.seek(self._pos)
OSError: [Errno 22] Invalid argument

Expected behavior

Kobo sync completes without error

Screenshots

See additional context

Environment:

  • OS: Debian 11 - Linux 6.1.0-18-amd64
  • Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
  • Calibre-Web version: 0.6.21 - c45188b - 2023-10-21T12:40:32+02:00
  • Docker container: LinuxServer
  • Browser: Chrome 123.0.6312.122

Additional context
When accessing the api directly from Chrome, calibre-web also returns a HTTP 500 error and traceback with the same error code.

Screenshot_20240421_201318

@OzzieIsaacs
Copy link
Collaborator

Please try to update to the newest nightly version. It should work.
The reason behind it: Calibre-Web trys to detect a "fixed-layout", needed for e.g. comic files in epub format. Your error was an unexpected error in this detection. Find the root cause of it and to deal better with it, it would be of interest for me to have the problematic book (or even better the relevant part of it). After update you should get a message like "Could not parse epub metadata of book xxx". If you could take this book (It's the id calibre-web showing in the link if you open a book), then open the (k)epub file of it with a zipper and send me the container.xml located in the META-INF folder (preferably via email found on my profile page, so nobody else has contact with your private book contents).

@sre3
Copy link
Author

sre3 commented Apr 29, 2024

Thanks for the quick reply! I'll switch to nightly tomorrow and grab the xml.

@sre3
Copy link
Author

sre3 commented May 1, 2024

Well... Ark will not let me open the epub, saying: Failed to open archive: Zip archive inconsistent

The Calibre epub editor also fails to open the book, saying

  File "calibre/ebooks/oeb/polish/container.py", line 1178, in __init__
  File "calibre/utils/zipfile.py", line 1113, in extractall
  File "calibre/utils/zipfile.py", line 1097, in extract
  File "calibre/utils/zipfile.py", line 1166, in _extract_member
  File "calibre/utils/zipfile.py", line 1035, in open
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/gui2/tweak_book/job.py", line 33, in run
  File "calibre/gui2/tweak_book/boss.py", line 82, in get_container
  File "calibre/ebooks/oeb/polish/container.py", line 1594, in get_container
  File "calibre/ebooks/oeb/polish/container.py", line 1184, in __init__
  File "calibre/utils/localunzip.py", line 252, in extractall
  File "calibre/utils/localunzip.py", line 234, in _extractall
  File "calibre/utils/localunzip.py", line 177, in copy_compressed_file
ValueError: Invalid ZIP file, local header is damaged

I will close the issue as this seems to be an issue with the file, and not calibre-web. Sync is also now working properly as the error is handled gracefully. Thanks again for the quick fix.

@sre3 sre3 closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants