1

Editing to create a minimal reproducible example: I am importing bitbucket and Bitbucket because even though the docs indicate 'bitbucket', I get errors that there is no attribute for repo_list; see below My code is:


from atlassian import Bitbucket
from atlassian import bitbucket
from atlassian.bitbucket import Cloud


bitbucket_username = 'username'
scraper_token = 'token'

Bitbucket_app_pw = Cloud(
    username=bitbucket_username,
    password=scraper_token,
    cloud=True)

try:
    repo_list = bitbucket.repo_list("SOL")
    print(repo_list)
    projects = bitbucket.project_list(Bitbucket_app_pw)
    print(projects)
    data = bitbucket.project("SOL")
    print(data)
    project_info = bitbucket.project("SOL")
    print(project_info)
except AttributeError:
    project_key = "SOL"
    repo_list = Bitbucket.repo_list("SOL")
    print(repo_list)
    projects = Bitbucket.project_list(Bitbucket_app_pw)
    print(projects)
    data = Bitbucket.project("SOL")
    print(data)
    project_info = Bitbucket.project("SOL")
    print(project_info)


My error is:

Traceback (most recent call last):
  File "C:\Users\name.name\PycharmProjects\bitbucket scraper\main.py", line 16, in <module>
    repo_list = bitbucket.repo_list("SOL")
AttributeError: module 'atlassian.bitbucket' has no attribute 'repo_list'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\name.name\PycharmProjects\bitbucket scraper\main.py", line 28, in <module>
    repo_list = Bitbucket.repo_list("SOL")
TypeError: Bitbucket.repo_list() missing 1 required positional argument: 'project_key'

Original Question_

I am trying to log into a Atlassian BitBucket repository using the App Password, and it looks like I am in. But when I try to get a list of repositories in a project (using https://atlassian-python-api.readthedocs.io/bitbucket.html), I keep on getting an error. For example, the project key that I am trying to access is 'SOL'. So when I run:

Bitbucket.project_list('SOL')

I get an error:

AttributeError: 'str' object has no attribute '_url_projects'

Not sure what I am doing wrong here. Any advice? TIA!

Editing after people left helpful comments: So when I tried the suggestion given by AKX:

data = bitbucket.project("SOL")
print(data)

The response was:

AttributeError: module 'atlassian.bitbucket' has no attribute 'project'
gottsman
  • 23
  • 5
  • Please show the complete code (including imports) as [example]. Usually `AttributeError`s depend on the state of the `object`, or if relating to `module` the [import statements](https://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute) (which we don't see currently). – hc_dev Feb 08 '22 at 09:29

2 Answers2

1

If you want to use atlassian.bitbucket.Cloud, you'd need something like

from atlassian.bitbucket import Cloud

bitbucket_username = 'username'
scraper_token = 'token'

bb = Cloud(
    username=bitbucket_username,
    password=scraper_token,
    cloud=True,
)

repo_list = bb.repo_list("SOL")
print(repo_list)
projects = bb.project_list()
print(projects)
data = bb.project("SOL")
print(data)
project_info = bb.project("SOL")
print(project_info)

Original

You will need to instantiate the Bitbucket class first; based on your spelling, you're trying to access an instance method.

Based on the examples in the docs:

from atlassian import Bitbucket

bitbucket = Bitbucket(
        url='http://localhost:8080',
        username='admin',
        password='admin')

data = bitbucket.project("SOL")
print(data)

(note that project_list() does not accept a parameter anyway; if you want a project's info, use project().)

AKX
  • 152,115
  • 15
  • 115
  • 172
1

From the docs on "Manage Projects" (you linked):

# Project list
bitbucket.project_list()

# Repo list
bitbucket.repo_list(project_key)

# Project info
bitbucket.project(key)

So don't use all-in-one with Bitbucket.project_list('SOL'). Instead create a client-instance as explained by AKX and then retrieve a single specific project bitbucket.project('SOL').

hc_dev
  • 8,389
  • 1
  • 26
  • 38