Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test api script with access token issue #252

Open
BoykaZhu opened this issue Oct 23, 2023 · 0 comments
Open

Test api script with access token issue #252

BoykaZhu opened this issue Oct 23, 2023 · 0 comments
Labels
examples An issue related to an example script

Comments

@BoykaZhu
Copy link

Hi,

When I try to use the command line to test the script, I always get auth token error:
Actually, the token works fine in my jenkinsfile.

Our BD is v2023.4.1.
Command line OS: Red Hat Enterprise Linux Server release 7.9 (Maipo)

Kindly help to review what is the cause.

[root@test001 client]# pip3 list
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Package             Version
------------------- ------------
arrow               1.2.3
attrs               22.2.0
blackduck           1.1.0
bleach              4.1.0
certifi             2023.7.22
cffi                1.15.1
charset-normalizer  2.0.12
colorama            0.4.5
cryptography        40.0.2
docutils            0.18.1
idna                3.4
importlib-metadata  4.8.3
importlib-resources 5.4.0
iniconfig           1.1.1
jeepney             0.7.1
keyring             23.4.1
packaging           21.3
pip                 21.3.1
pkginfo             1.9.6
pluggy              1.0.0
py                  1.11.0
pycparser           2.21
Pygments            2.14.0
pyparsing           3.1.1
pytest              7.0.1
pytest-datadir      1.4.1
pytest-html         3.2.0
pytest-metadata     1.11.0
python-dateutil     2.8.2
pytz                2023.3.post1
readme-renderer     34.0
requests            2.27.0
requests-mock       1.11.0
requests-toolbelt   1.0.0
rfc3986             1.5.0
SecretStorage       3.3.3
setuptools          39.2.0
six                 1.16.0
terminaltables      3.1.10
timestring          1.6.4
tomli               1.2.3
tqdm                4.64.1
twine               3.8.0
typing_extensions   4.1.1
urllib3             1.26.18
webencodings        0.5.1
wheel               0.37.1
zipp                3.6.0
[root@test001 client]# python3 quickstart.py --base-url "https://bdstage01.blackducksoftware.com" --token-file ../../restconfig.json.api_token
[2023-10-23 01:43:30,936] {Client:50} INFO - Using a session with a 15.0 second timeout and up to 3 retries per request
[2023-10-23 01:43:30,938] {connectionpool:1023} DEBUG - Starting new HTTPS connection (1): bdstage01.blackducksoftware.com:443
[2023-10-23 01:43:31,427] {connectionpool:483} DEBUG - https://bdstage01.blackducksoftware.com:443 "POST /api/tokens/authenticate HTTP/1.1" 401 None
[2023-10-23 01:43:31,429] {Authentication:77} ERROR - HTTP response status code = 401 (Unauthorized)
[2023-10-23 01:43:31,429] {Authentication:79} ERROR - Request failed authorization
Traceback (most recent call last):
  File "quickstart.py", line 27, in <module>
    for project in bd.get_resource('projects'):
  File "/usr/local/lib/python3.6/site-packages/blackduck/Client.py", line 168, in get_resource
    resources_dict = self.list_resources(parent)
  File "/usr/local/lib/python3.6/site-packages/blackduck/Client.py", line 126, in list_resources
    resp = self.session.get("/api/")
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 542, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/blackduck/Client.py", line 66, in request
    return super().request(method, url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 515, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 453, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 322, in prepare
    self.prepare_auth(auth, url)
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 558, in prepare_auth
    r = auth(self)
  File "/usr/local/lib/python3.6/site-packages/blackduck/Authentication.py", line 43, in __call__
    self.authenticate()
  File "/usr/local/lib/python3.6/site-packages/blackduck/Authentication.py", line 84, in authenticate
    raise RuntimeError("Unauthorized access token", response)
RuntimeError: ('Unauthorized access token', <Response [401]>)
[root@test001 client]#

Thanks
bz.

@OffBy0x01 OffBy0x01 added the examples An issue related to an example script label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples An issue related to an example script
Projects
None yet
Development

No branches or pull requests

2 participants