urschrei / pyzotero

Pyzotero: a Python client for the Zotero API
https://pyzotero.readthedocs.org
Other
908 stars 99 forks source link

Pyzotero.dump() not working. Response: Not found #175

Closed Tomptez closed 5 months ago

Tomptez commented 8 months ago

Hello, for some reason pyzotero.dump() stopped working for me. The file definitely exists in the library. I am using the lates version of pyzotero.

I tried using

with open('article.pdf', 'wb') as f:
    f.write(zot.file())

instead but it didn't work either

Platform: Fedora 39 Python version: 3.12.2 Pyzotero version: 1.5.18

Problem Description

More Details

Traceback zot.dump("N4MTZ5LU") Traceback (most recent call last): File "$MYPATH/venv/lib64/python3.12/site-packages/pyzotero/zotero.py", line 426, in _retrieve_data self.request.raise_for_status() File "$MYPATH/venv/lib64/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.zotero.org/groups/2364338/items/N4MTZ5LU/file The above exception was the direct cause of the following exception: Traceback (most recent call last): File "", line 1, in File "$MYPATH/venv/lib64/python3.12/site-packages/pyzotero/zotero.py", line 734, in dump file = self.file(itemkey) ^^^^^^^^^^^^^^^^^^ File "$MYPATH/venv/lib64/python3.12/site-packages/pyzotero/zotero.py", line 179, in wrapped_f retrieved = self._retrieve_data(func(self, *args)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "$MYPATH/venv/lib64/python3.12/site-packages/pyzotero/zotero.py", line 428, in _retrieve_data error_handler(self, self.request, exc) File "$MYPATH/LitFilter_Repo/venv/lib64/python3.12/site-packages/pyzotero/zotero.py", line 1660, in error_handler raise error_codes.get(req.status_code)(err_msg(req)) from exc pyzotero.zotero_errors.ResourceNotFound: Code: 404 URL: https://api.zotero.org/groups/2364338/items/N4MTZ5LU/file Method: GET Response: Not found
urschrei commented 8 months ago

I can't reproduce this: both file() and dump() are working as expected. If you're getting a 404 error that suggests the attachment doesn't exist on the Zotero server, possibly due to a sync issue or typo. Are you sure that you're passing the ID of a file attachment to the file \ dump call? The 404 URL doesn't look correct to me; it should be something like https://api.zotero.org/users/436/items/H3XDWRWX?format=json&limit=100

Tomptez commented 8 months ago

Hm, not sure where to go from here.

The code has worked previously, I haven't made any changes, but of course some sync issues could be part of that.

But I can access said attachment via the api.

This URL I can access via my browser:

https://api.zotero.org/groups/2364338/items/MC44N87M/

But using the pyzotero.dump() call it seems to call:

https://api.zotero.org/groups/2364338/items/MC44N87M/file

which produces the 404 error.

I create the zotero instance like this:

zot = zotero.Zotero(libraryID, "group", APIkey)

and try to get the pdfs like this:

attachments = zot.children(articleID)

    for each in attachments:
        try:
            if each["data"]["itemType"] == "attachment":
                if each["data"]["contentType"] == 'application/pdf':
                    pdfID = each["data"]["key"]
                    zot.dump(pdfID)

and I think that code is working, as I can access the attachment via the API. It is just that the /file call is producing the 404 error.

urschrei commented 5 months ago

Please reopen if need be, but I can't reproduce.