calibre upload errors
This commit is contained in:
@@ -14,7 +14,8 @@ import sftp as sftp_module
|
|||||||
import sync
|
import sync
|
||||||
import uploader
|
import uploader
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s — %(message)s")
|
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(name)s — %(message)s")
|
||||||
|
logging.getLogger("paramiko").setLevel(logging.INFO) # paramiko debug is too noisy
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
_scheduler = BackgroundScheduler(timezone="UTC")
|
_scheduler = BackgroundScheduler(timezone="UTC")
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ class CalibreClient:
|
|||||||
if not self._upload_csrf:
|
if not self._upload_csrf:
|
||||||
page = self._session.get(f"{self._cfg.url}/upload", timeout=30)
|
page = self._session.get(f"{self._cfg.url}/upload", timeout=30)
|
||||||
self._upload_csrf = _extract_csrf(page.text)
|
self._upload_csrf = _extract_csrf(page.text)
|
||||||
|
log.debug("Upload CSRF token: %s", self._upload_csrf[:12] + "…" if self._upload_csrf else "NOT FOUND")
|
||||||
|
|
||||||
mime = MIME_TYPES.get(book_path.suffix.lower(), "application/octet-stream")
|
mime = MIME_TYPES.get(book_path.suffix.lower(), "application/octet-stream")
|
||||||
with book_path.open("rb") as fh:
|
with book_path.open("rb") as fh:
|
||||||
@@ -72,10 +73,15 @@ class CalibreClient:
|
|||||||
data={"csrf_token": self._upload_csrf} if self._upload_csrf else {},
|
data={"csrf_token": self._upload_csrf} if self._upload_csrf else {},
|
||||||
timeout=120,
|
timeout=120,
|
||||||
)
|
)
|
||||||
|
if not resp.ok:
|
||||||
|
log.error("Upload HTTP %s — response body: %s", resp.status_code, resp.text[:500])
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
log.info("Uploaded: %s", book_path.name)
|
log.info("Uploaded: %s", book_path.name)
|
||||||
db.record_book(book_path.name, file_hash, zip_source, "uploaded")
|
db.record_book(book_path.name, file_hash, zip_source, "uploaded")
|
||||||
return "uploaded"
|
return "uploaded"
|
||||||
|
except requests.HTTPError:
|
||||||
|
db.record_book(book_path.name, file_hash, zip_source, "error")
|
||||||
|
return "error"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Upload failed for %s: %s", book_path.name, e)
|
log.error("Upload failed for %s: %s", book_path.name, e)
|
||||||
db.record_book(book_path.name, file_hash, zip_source, "error")
|
db.record_book(book_path.name, file_hash, zip_source, "error")
|
||||||
|
|||||||
Reference in New Issue
Block a user