vzhd1701 / evernote-backup

Backup & export all Evernote notes and notebooks
MIT License
989 stars 76 forks source link

[Bug]: Error exporting notes #38

Closed twobaker closed 1 year ago

twobaker commented 1 year ago

evernote-backup version

1.9.2

What OS are you using?

Windows

OS Version / Linux distribution

Windows 10

Bug description

Sync and auth works fine, but exporting notes give an error. Allways same notebook (8 from 91), no matter if single export or notebook export.

Log excerpt

(--verbose doesn't work), but in screen
Reading database en_backup.db...
Exporting notes...
  [###---------------------------------]  8/91  00:12:29
Traceback (most recent call last):
  File "evernote_backup\cli.py", line 305, in main
  File "click\core.py", line 1130, in __call__
  File "click\core.py", line 1055, in main
  File "click\core.py", line 1657, in invoke
  File "click\core.py", line 1404, in invoke
  File "click\core.py", line 760, in invoke
  File "evernote_backup\cli.py", line 260, in export
  File "evernote_backup\cli_app.py", line 160, in export
  File "evernote_backup\note_exporter.py", line 64, in export_notebooks
  File "evernote_backup\note_exporter.py", line 88, in _export_active
  File "evernote_backup\note_exporter.py", line 99, in _export_notes
  File "evernote_backup\note_exporter.py", line 122, in _output_notebook
  File "evernote_backup\note_exporter.py", line 154, in _write_export_file
  File "evernote_backup\note_formatter.py", line 25, in format_note
  File "evernote_backup\note_formatter_util.py", line 14, in fmt_time
OSError: [Errno 22] Invalid argument
Houska1 commented 1 year ago

I had the exact same problem right now. The culprit in my case was a single note whose creation date, as reported within EN 10, was Tuesday, 16 Dec 1969, 04:29. This is clearly erroneous and some glitch in the EN database itself. Nevertheless, evernote-backup needs to handle bad creation (and other(?)) dates more gracefully. According to https://docs.python.org/3/library/datetime.html#datetime-objects, need to expect OverflowError or OSError for dates prior to 1970.

In my case, this one note was no longer useful, so I deleted it and expunged it from Trash in EN itself. Then, after a sync to capture that change, exporting worked normally.

Thanks for a great tool!

Editing to add: I've kept an Evernote-Legacy exported .enex of the faulty note if helpful, but the only remarkable thing about it is the clearly corrupt <created>19691216T092941Z</created> which is what makes fmt_time, line 14 choke.

Houska1 commented 1 year ago

I'm not running on a machine where I can try changing python code, but perhaps this special case, which is erroneous data within EN itself, could be simply caught with a try: ... except: return None in fmt_time in note_formatter_util.py? This would match the None returned by if timestamp is None: return timestamp on line 8.

favoyang commented 1 year ago

It may be caused by an invalid timestamp (for me it's a negative timestamp). I fixed it in PR #48.

Alternatively, you can try...catch the OSError and simply ignore all cases.

sergeevabc commented 9 months ago

Windows 7 x64, evernote-backup 1.9.3

$ evernote-backup
Usage: evernote-backup.exe [OPTIONS] COMMAND [ARGS]...
Try 'evernote-backup.exe --help' for help.

$ evernote-backup --single-notes export ./myfiles
Error: No such option: --single-notes

$ evernote-backup export --single-notes ./myfiles
Reading database en_backup.db...
Exporting notebooks...
  [#################-------------------]  9/19  00:00:12
Traceback (most recent call last):
  File "evernote_backup\cli.py", line 305, in main
  File "click\core.py", line 1157, in __call__
  File "click\core.py", line 1078, in main
  File "click\core.py", line 1688, in invoke
  File "click\core.py", line 1434, in invoke
  File "click\core.py", line 783, in invoke
  File "evernote_backup\cli.py", line 260, in export
  File "evernote_backup\cli_app.py", line 160, in export
  File "evernote_backup\note_exporter.py", line 64, in export_notebooks
  File "evernote_backup\note_exporter.py", line 88, in _export_active
  File "evernote_backup\note_exporter.py", line 97, in _export_notes
  File "evernote_backup\note_exporter.py", line 115, in _output_single_notes
  File "evernote_backup\note_exporter.py", line 128, in _write_export_file
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\myfiles\\loooooong.enex'

Two failures here: