blackducksoftware / hub-rest-api-python

HUB REST API Python bindings
Apache License 2.0
89 stars 104 forks source link

Set accept and content-type headers to application/vnd.blackducksoftware.user-4+json #203

Closed exzz closed 1 year ago

exzz commented 2 years ago

Hi,

According to documentation and my tests, accept and content-type headers need to be set to application/vnd.blackducksoftware.user-4+json. If not, some request may fail with 406 error code (for example http//BLACKDUCK_URL/api/users/USER_UID/last-login).

I would recommend to change Client.py code :

if 'accept' not in lc_keys and 'content-type' not in lc_keys:
                # set default media type only if neither 'accept' nor 'content-type'
                # exist as some endpoints may only accept one or the other but not both
                lc_keys['accept'] = "application/json"
                lc_keys['content-type'] = "application/json"

to

if 'accept' not in lc_keys and 'content-type' not in lc_keys:
                # set default media type only if neither 'accept' nor 'content-type'
                # exist as some endpoints may only accept one or the other but not both
                lc_keys['accept'] = "application/vnd.blackducksoftware.user-4+json"
                lc_keys['content-type'] = "application/vnd.blackducksoftware.user-4+json"
OffBy0x01 commented 1 year ago

Most endpoints use their own content type versioning. By design, client provides sensible defaults that can easily be overridden by users.

Headers can be passed to the underlying request via the kwargs.