pyzotero icon indicating copy to clipboard operation
pyzotero copied to clipboard

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

Open Tomptez opened this issue 11 months ago • 2 comments

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

  • What were you trying to do? I was trying to download a pdf file from a collection
    • What API call did it involve pyzotero.dump()
    • What error was raised? See below

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 "<stdin>", line 1, in <module>
      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

Tomptez avatar Mar 21 '24 14:03 Tomptez

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

urschrei avatar Mar 22 '24 18:03 urschrei

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.

Tomptez avatar Mar 26 '24 09:03 Tomptez

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

urschrei avatar Jun 17 '24 20:06 urschrei