blackducksoftware / hub-rest-api-python

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

x-csrf-token does not exist #216

Closed winmike closed 2 years ago

winmike commented 2 years ago

Calling the scan_docker_image.py to verify an image, following error appears (s. below). self.token, self.csrf_token, self.cookie = self.get_auth_token() results in return self._store[key.lower()][1] KeyError: 'x-csrf-token'

Does it mean, the blackduck server response doesn't contain this header? What can be the reason - failed authentication?

_Traceback (most recent call last): File "/home/vsts/work/1/s/pipelines/blackduck/scan_docker_image_layers.py", line 538, in sys.exit(main()) File "/home/vsts/work/1/s/pipelines/blackduck/scan_docker_image_layers.py", line 528, in main scan_container_image(args.imagespec) File "/home/vsts/work/1/s/pipelines/blackduck/scan_docker_image_layers.py", line 413, in scan_container_image hub = HubInstance() File "/home/vsts/.local/lib/python3.8/site-packages/blackduck/HubRestApi.py", line 157, in init self.token, self.csrf_token, self.cookie = self.get_auth_token() File "/home/vsts/.local/lib/python3.8/site-packages/blackduck/Core.py", line 35, in get_auth_token csrf_token = response.headers['X-CSRF-TOKEN'] File "/usr/lib/python3/dist-packages/requests/structures.py", line 52, in getitem return self.store[key.lower()][1] KeyError: 'x-csrf-token'

shivabhatnutanix commented 2 years ago

Seeing the same ussye

hub = HubInstance() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/site-packages/blackduck/HubRestApi.py", line 155, in init self.token, self.csrf_token, self.cookie = self.get_auth_token() File "/usr/local/lib/python3.6/site-packages/blackduck/Core.py", line 35, in get_auth_token csrf_token = response.headers['X-CSRF-TOKEN'] File "/usr/local/lib/python3.6/site-packages/requests/structures.py", line 54, in getitem return self._store[key.lower()][1] KeyError: 'x-csrf-token'

subhamsps commented 2 years ago

i believe you might have added a '/' at the end of the url in .restconfig.json , please remove the '/' and try again

winmike commented 2 years ago

Indeed: the removal of the trailing slash did the trick Thank you!

dineshr93 commented 11 months ago

In my case below steps worked

$ apt remove python3-pip
$ apt install python3-pip
$ pip3 install pyOpenSSL --upgrade
$ pip3 install blackduck