Problem with `Resource.upload`
First of all, I really like the new client, since it provides the same hierarchy as found on CoScInE! Thanks a lot!
However, I have some problems to upload files via the python client right now. I tried the following code
from coscine import Client
with open('../CoScInE_token2.txt') as f:
token = f.read()
c = Client(token=token, verbose=False)
prs = c.projects()
pr = prs[1]
print(f"Project: ID={pr.data['id']} slug={pr.data['slug']}")
res = pr.resources()[2]
mtdf = res.MetadataForm()
mtdf['ID'] = '1'
mtdf["User"] = 'Me'
print(f"Resource: ID={res.data['id']}")
c.verbose = True
res.upload(key='some_key', file='../Documents/empty.txt', metadata=mtdf)
and got this output:
Project: ID=e1983a56-ee35-413e-9a66-771196c0a089 slug=testproject-9522
Resource: ID=abb54be4-9e91-4242-98aa-5f1c883c0f9c
[REQUEST] PUT https://coscine.rwth-aachen.de/coscine/api/Coscine.Api.Tree/Tree/abb54be4-9e91-4242-98aa-5f1c883c0f9c/some_key
[DATA] {
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
{
"type": "uri",
"value": "https://purl.org/coscine/ap/sfb1394/CalphadDB/"
}
],
"http://purl.org/dc/terms/identifier": [
{
"value": "1",
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"type": "literal"
}
],
"http://purl.org/dc/terms/creator": [
{
"value": "Me",
"datatype": "http://www.w3.org/2001/XMLSchema#string",
"type": "literal"
}
]
}
Traceback (most recent call last):
File "C:\Users\Siemer\anaconda3\envs\pyinstaller\lib\site-packages\coscine\client.py", line 153, in _request
response.raise_for_status()
File "C:\Users\Siemer\anaconda3\envs\pyinstaller\lib\site-packages\requests\models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://coscine.rwth-aachen.de/coscine/api/Coscine.Api.Tree/Tree/abb54be4-9e91-4242-98aa-5f1c883c0f9c/some_key
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Siemer/Downloads/CoScInE_API-Copy1.py", line 17, in <module>
res.upload(key='some_key', file='../Documents/empty.txt', metadata=mtdf)
File "C:\Users\Siemer\anaconda3\envs\pyinstaller\lib\site-packages\coscine\resource.py", line 67, in upload
self.client.put(uri, data = metadata)
File "C:\Users\Siemer\anaconda3\envs\pyinstaller\lib\site-packages\coscine\client.py", line 176, in put
return self._request("PUT", uri, **kwargs)
File "C:\Users\Siemer\anaconda3\envs\pyinstaller\lib\site-packages\coscine\client.py", line 166, in _request
raise RequestException()
requests.exceptions.RequestException
Process finished with exit code 1
I am not sure if I made a mistake somewhere or if this is a real issue. Thanks for looking into this!