atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Bitbcket cloud get

Open morettimaxi opened this issue 4 years ago • 7 comments

I tested and the user and password works

# coding=utf-8

from atlassian import Jira
from atlassian import Confluence
from atlassian import Bitbucket
from atlassian import ServiceDesk
from atlassian import Xray
from atlassian.bitbucket import Cloud

bitbucket = Cloud(url="https://api.bitbucket.org/", username="xxxx", password="xxxx")



print(bitbucket.all_project_administrators())

But I ahve this error when I try to execute a function:

python.exe .\main2.py Traceback (most recent call last): File "main2.py", line 14, in <module> print(bitbucket.all_project_administrators()) AttributeError: 'Cloud' object has no attribute 'all_project_administrators'

morettimaxi avatar Jul 12 '21 20:07 morettimaxi

This function is implemented in the Bitbucket object and not in the neww OO interface Cloud. Replace Cloud with Bitbucket and add the kwarg cloud=True.

Spacetown avatar Jul 12 '21 20:07 Spacetown

Thanks @Spacetown I tried it but i have the following error:

`from atlassian import Bitbucket

bitbucket = Bitbucket( url='https://api.bitbucket.org', username=xxxxxx', password='xxxxxx', cloud=True)

data = bitbucket.project_list() print(data)`

python.exe .\main.py <generator object BitbucketBase._get_paged at 0x000001A3901CDA50>

morettimaxi avatar Jul 13 '21 12:07 morettimaxi

Try putting the request in a list(). That'll make it printable with print.

data = list(bitbucket.project_list())

It is actually not an error. The function just returns a generator object, which you can iterate through. But printing it will just output that it is a generator. The list function converts it to a list, which can be printed well.

jensvog avatar Jul 13 '21 13:07 jensvog

@jensvog @Spacetown I tried it but it has a 404. I am using Btbucket Cloud, Is it works in cloud?

`from atlassian import Bitbucket

bitbucket = Bitbucket(
        url='https://api.bitbucket.org',
        username='xxx',
        password='xxxxxq',
        cloud=True)

data = list(bitbucket.project_list())


print(data)`
.
python.exe .\main.py
Traceback (most recent call last):
  File "C:\projects\zenfolio\bitbucket\main.py", line 9, in <module>
    data = list(bitbucket.project_list())
  File "C:\Users\Max\AppData\Local\Programs\Python\Python39\lib\site-packages\atlassian\bitbucket\base.py", line 59, in _get_paged
    response = self.get(url, trailing=trailing, params=params, data=data, flags=flags, absolute=absolute)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python39\lib\site-packages\atlassian\rest_client.py", line 264, in get
    response = self.request(
  File "C:\Users\Max\AppData\Local\Programs\Python\Python39\lib\site-packages\atlassian\rest_client.py", line 236, in request
    self.raise_for_status(response)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python39\lib\site-packages\atlassian\rest_client.py", line 386, in raise_for_status
    response.raise_for_status()
  File "C:\Users\Max\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.bitbucket.org/2.0/projects

morettimaxi avatar Jul 13 '21 17:07 morettimaxi

That's because the cloud path seems to be outdated. I think only the functions which have a workspace as argument and the Cloud object are working.

Spacetown avatar Jul 13 '21 18:07 Spacetown

@Spacetown Do you know where i can et the documentation about cloud?

morettimaxi avatar Jul 13 '21 19:07 morettimaxi

Please check the example https://github.com/atlassian-api/atlassian-python-api/blob/master/examples/bitbucket/bitbucket_cloud_oo.py and the tests.

Spacetown avatar Jul 13 '21 20:07 Spacetown