e-alizadeh / Zotero2Readwise

A Python Library to retrieve annotations and notes from Zotero and upload them to your Readwise.
MIT License
131 stars 24 forks source link

Feature request: Truncate creator/author field if it exceeds 1024 characters #58

Closed stephan-koenig closed 11 months ago

stephan-koenig commented 1 year ago

Hi!

Thank you for your library!

Description of error

I have tried to import my Zotero annotations to Readwise but get the following error (both as a GitHub Actions Workflow and on my local machine):

Retrieving ALL annotations from Zotero Database. 
It may take some time...

282 Zotero items are retrieved.
ZOTERO: Start formatting 282 annotations/notes...
It may take some time depending on the number of annotations...
A complete message will show up once it's done!

ZOTERO: Formatting Zotero Items is completed!!

Readwise: Push 282 Zotero annotations/notes to Readwise...
It may take some time depending on the number of highlights...
A complete message will show up once it's done!

Traceback (most recent call last):
  File "/Users/stephan/Documents/GitHub/workflows/run.py", line 64, in <module>
    zt2rw.run()
  File "/Users/stephan/Library/r-miniconda/envs/test/lib/python3.9/site-packages/zotero2readwise/zt2rw.py", line 55, in run
    self.readwise.post_zotero_annotations_to_readwise(formatted_items)
  File "/Users/stephan/Library/r-miniconda/envs/test/lib/python3.9/site-packages/zotero2readwise/readwise.py", line 149, in post_zotero_annotations_to_readwise
    self.create_highlights(rw_highlights)
  File "/Users/stephan/Library/r-miniconda/envs/test/lib/python3.9/site-packages/zotero2readwise/readwise.py", line 72, in create_highlights
    raise Zotero2ReadwiseError(
zotero2readwise.exception.Zotero2ReadwiseError: Uploading to Readwise failed with following details:
POST request Status Code=400 (Bad Request)
Error log is saved to error_log_400_failed_post_request_to_readwise.json file.

The error_log_400_failed_post_request_to_readwise.json indicates for 29 items:

{"author": ["Ensure this field has no more than 1024 characters."]}

Proposed solution

After concatenating all creators while importing a Zotero item, would it be possible to check if the string exceeds 1024 characters, and if it does, replace it with <last name of first author> et al.? Considering how prevalent a large number of authors is nowadays in some fields, I imagine many people will encounter that problem.

Probably relates to https://github.com/e-alizadeh/Zotero2Readwise/issues/43 and https://github.com/e-alizadeh/Zotero2Readwise/issues/27.

stephan-koenig commented 11 months ago

@e-alizadeh, I don't think the PR fully resolved the issue. Both using a GitHub Action workflow and a local install of your library (v4.2) still fails for me, but now error_log_400_failed_post_request_to_readwise.json indicates only for a single item:

{"author": ["Ensure this field has no more than 1024 characters."]}