Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tomptez opened this issue Mar 21, 2024 · 2 comments
Open

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

Tomptez opened this issue Mar 21, 2024 · 2 comments
Assignees

Comments

@Tomptez
Copy link

Tomptez commented Mar 21, 2024

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
@urschrei
Copy link
Owner

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
Copy link
Author

Tomptez commented Mar 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants