atlassian-api / atlassian-python-api

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

Issue WIth Bitbucket Api #1259

Closed YasirKusay closed 12 months ago

YasirKusay commented 12 months ago
from atlassian.bitbucket import Bitbucket

bb = Bitbucket(url="https://api.bitbucket.org/", username="ATLASSIAN_USERNAME", password="BITBUCKET_APP_KEY", cloud=True)

list(bb.project_list())

When executing the final command, I get an error like this:

  File "<stdin>", line 1, in <module>
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/base.py", line 66, in _get_paged
    response = 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/rest_client.py", line 493, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError

I get a similar error when executing other commands, could you please tell me what the problem is?

YasirKusay commented 12 months ago

I printed the error code and I got a 404 error. After playing around with the code, I believe it may be an issue to do with the url, could you please tell me what I should do?

YasirKusay commented 12 months ago

Update 2, I changed the URL to be https://bitbucket.org/{name_of_workspace}/workspace/projects/,

I think this makes more sense, however I am now getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/anaconda3/lib/python3.11/site-packages/atlassian/bitbucket/base.py", line 66, in _get_paged
    response = 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/rest_client.py", line 478, in raise_for_status
    raise HTTPError("Unauthorized (401)", response=response)
requests.exceptions.HTTPError: Unauthorized (401)
YasirKusay commented 12 months ago

Update 3, I finally got this to work using the solution provided in https://community.atlassian.com/t5/Confluence-Cloud-questions/How-to-connect-to-Atlassian-python-API-using-Auth-2-0-Bearer/qaq-p/2231700.

However, only admins can set up Oauth Keys. Is it possible to have another solution (i.e. using keys that belong to a user that is authorised to make changes to a repo).