atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 643 forks source link

Repo Access Token not Working #1260

Open YasirKusay opened 9 months ago

YasirKusay commented 9 months ago

I created a repository access token and I ran the below code to get my issues for a repo

from atlassian.bitbucket import Bitbucket
bb = Bitbucket(url='https://api.bitbucket.org/', token='REPO_ACCESS_TOKEN', cloud=True)
bb.get_issues(workspace, repo)

However, I got the error:

can only concatenate str (not "dict") to str
Traceback (most recent call last):
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/cloud/base.py", line 116, in raise_for_status
    error_msg += "\n" + e["detail"]
                 ~~~~~^~~~~~~~~~~~~
TypeError: can only concatenate str (not "dict") to str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/anaconda3/lib/python3.11/site-packages/deprecated/classic.py", line 285, in wrapper_function
    return wrapped_(*args_, **kwargs_)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/__init__.py", line 3297, in get_issues
    for p in (
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/cloud/repositories/issues.py", line 52, in each
    for issue in self._get_paged(None, params=params):
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/cloud/base.py", line 71, in _get_paged
    response = super(BitbucketCloudBase, self).get(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/rest_client.py", line 288, in get
    response = self.request(
               ^^^^^^^^^^^^^
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/rest_client.py", line 260, in request
    self.raise_for_status(response)
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/cloud/base.py", line 119, in raise_for_status
    response.raise_for_status()
  File "~/anaconda3/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.bitbucket.org/2.0/repositories/{WORKSPACE}/{TEST}/issues

(I have hidden the workspace name and repo name in the final line)

I got a similar error when running this:

from atlassian.bitbucket import Bitbucket
import requests

s = requests.Session()
s.headers['Authorization'] = 'Bearer REPO_ACCESS_TOKEN'

bb = Bitbucket(url='https://api.bitbucket.org/', session=s', cloud=True)
bb.get_issues(workspace, repo)
gonchik commented 8 months ago

@YasirKusay Did you figure out that problem ?

YasirKusay commented 8 months ago

@gonchik , Yes, will post how I did it later