cthoyt / zenodo-client

A tool for automated uploading and version management of scientific data to Zenodo
MIT License
25 stars 5 forks source link

Records IDs in config mistakenly shared by sandbox.zenodo.org and zenodo.org #5

Closed mberr closed 1 year ago

mberr commented 2 years ago

I first test creating an upload using sandbox=True

ensure_zenodo(key="key", data=data, paths=paths, sandbox=True)

Once this worked successfully, this will store the record ID into the config file located at ~/.config/zenodo.ini:

[zenodo]
sandbox_api_token = SOME_TOKEN
api_token = SOME_OTHER_TOKEN
key = 1234567 # <- this is the new key within the sandbox

Now, I want to actually publish the record and thus switch to sandbox=False, i.e.,

ensure_zenodo(key="key", data=data, paths=paths, sandbox=False)

Since the stored record ID does not contain the information that this ID exists within the sandbox environment only, the code will assume that the record should already exist and try to update it. This leads to a 404 error:

Traceback (most recent call last):
  File "upload.py", line 102, in <module>
    main()
  File "...zenodo-tools/venv/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "...zenodo-tools/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "...zenodo-tools/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "...zenodo-tools/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "upload.py", line 92, in main
    res = ensure_zenodo(
  File "...zenodo-client/src/zenodo_client/api.py", line 48, in ensure_zenodo
    return update_zenodo(deposition_id, paths, **kwargs)
  File "...zenodo-client/src/zenodo_client/api.py", line 64, in update_zenodo
    return Zenodo(**kwargs).update(deposition_id, paths)
  File "...zenodo-client/src/zenodo_client/api.py", line 171, in update
    res.raise_for_status()
  File "...zenodo-tools/venv/lib/python3.8/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://zenodo.org/api/deposit/depositions/1234567/actions/newversion?access_token=<SOME_TOKEN>

A hotfix is to manually remove the record ID again.

sgbaird commented 1 year ago

@cthoyt will you publish a new package version so this can be exposed via pip install zenodo-client?

In the meantime, I'll pip install git+https://github.com/cthoyt/zenodo-client.git

cthoyt commented 1 year ago

@sgbaird done