cthoyt / zenodo-client

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

Sandbox.Zenodo: `HTTPError: 403 Client Error: FORBIDDEN for url: https://sandbox.zenodo.org/api/deposit/depositions?access_token=<access_token>` #9

Closed sgbaird closed 1 year ago

sgbaird commented 1 year ago

For sandbox.zenodo I'm getting:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In[8], line 23
     21 key = f"matsciopt-{task_name}-benchmark-dataset"
     22 access_token = ZENODO_SANDBOX_API_KEY if sandbox else ZENODO_API_KEY
---> 23 res = ensure_zenodo(
     24     key,
     25     data=data,
     26     paths=[
     27         f"data/processed/{task_name}/sobol_probability_filter.csv",
     28         f"data/processed/{task_name}/sobol_regression.csv",
     29         f"data/processed/{task_name}/model_metadata.json",
     30         f"models/{task_name}/surrogate_models.pkl",
     31         f"models/{task_name}/cross_validation_models_0.pkl",
     32         f"models/{task_name}/cross_validation_models_1.pkl",
     33         f"models/{task_name}/cross_validation_models_2.pkl",
     34         f"models/{task_name}/cross_validation_models_3.pkl",
     35         f"models/{task_name}/cross_validation_models_4.pkl",
     36     ],
     37     sandbox=sandbox,  # remove this when you're ready to upload to real Zenodo
     38     access_token=access_token,
     39 )
     40 from pprint import pprint
     42 pprint(res.json())

File c:\Users\sterg\Miniconda3\envs\matsci-opt-benchmarks\lib\site-packages\zenodo_client\api.py:37, in ensure_zenodo(key, data, paths, **kwargs)
     35 def ensure_zenodo(key: str, data: Data, paths: Paths, **kwargs) -> requests.Response:
     36     """Create a Zenodo record if it doesn't exist, or update one that does."""
---> 37     return Zenodo(**kwargs).ensure(key=key, data=data, paths=paths)

File c:\Users\sterg\Miniconda3\envs\matsci-opt-benchmarks\lib\site-packages\zenodo_client\api.py:101, in Zenodo.ensure(self, key, data, paths)
     98     logger.info("mapped local key %s to deposition %s", key, deposition_id)
     99     return self.update(deposition_id=deposition_id, paths=paths)
--> 101 res = self.create(data=data, paths=paths)
    102 # Write the ID to the key in the local configuration
    103 # so it doesn't need to be created from scratch next time
    104 pystow.write_config(self.module, key, str(res.json()["id"]))

File c:\Users\sterg\Miniconda3\envs\matsci-opt-benchmarks\lib\site-packages\zenodo_client\api.py:126, in Zenodo.create(self, data, paths)
    117     data = {
    118         "metadata": {key: value for key, value in data.dict(exclude_none=True).items() if value},
    119     }
    121 res = requests.post(
    122     self.depositions_base,
    123     json=data,
    124     params={"access_token": self.access_token},
    125 )
--> 126 res.raise_for_status()
    128 res_json = res.json()
    129 bucket = res_json.get("links", {}).get("bucket")

File c:\Users\sterg\Miniconda3\envs\matsci-opt-benchmarks\lib\site-packages\requests\models.py:1021, in Response.raise_for_status(self)
   1016     http_error_msg = (
   1017         f"{self.status_code} Server Error: {reason} for url: {self.url}"
   1018     )
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 403 Client Error: FORBIDDEN for url: https://sandbox.zenodo.org/api/deposit/depositions?access_token=<access_token>
cthoyt commented 1 year ago

This might be solved with the new release where I improved management of authorization between the production and sandbox instances

sgbaird commented 1 year ago

Hmm, I updated to zenodo-client-0.3.1 and am still getting this issue with sandbox=True. At least in the error message, the access token is the correct one.

It seems to work now. I refreshed my access tokens and restarted the Jupyter notebook kernel. It seems to work for both sandbox and non-sandbox now. Thanks!

cthoyt commented 1 year ago

@sgbaird great! feel free to open a new issue if there are any additional problems with authorization