web client: known() method raise "400 Client Error" traceback
The known() endpoint of swh.web.client used to work but now seems to systematically fail with a HTTP 400 client error, e.g.:
from swh.web.client.client import WebAPIClient
cli = WebAPIClient()
cli.known("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1")
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-2-ca0df2977e77> in <module>
----> 1 cli.known("swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1")
~/dati/projects/sw-heritage/git/swh-environment/swh-web-client/swh/web/client/client.py in known(self, swhids, **req_args)
428
429 """
--> 430 r = self._call(
431 "known/", http_method="post", json=list(map(str, swhids)), **req_args
432 )
~/dati/projects/sw-heritage/git/swh-environment/swh-web-client/swh/web/client/client.py in _call(self, query, http_method, **req_args)
198 elif http_method == "post":
199 r = requests.post(url, **req_args, headers=headers)
--> 200 r.raise_for_status()
201 elif http_method == "head":
202 r = requests.head(url, **req_args, headers=headers)
~/.cache/virtualenvs/swh/lib/python3.9/site-packages/requests/models.py in raise_for_status(self)
941
942 if http_error_msg:
--> 943 raise HTTPError(http_error_msg, response=self)
944
945 def close(self):
HTTPError: 400 Client Error: Bad Request for url: https://archive.softwareheritage.org/api/1/known/
The same request works fine with curl:
curl --silent \
--header "Content-Type: application/json" \
--request POST \
--data "[\"swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1\"]" \
https://archive.softwareheritage.org/api/1/known/ | jq
{
"swh:1:cnt:fe95a46679d128ff167b7c55df5d02356c5a1ae1": {
"known": true
}
}
Migrated from T3317 (view on Phabricator)