Python-Redmine on a project without issues

I have a Redmine project that is a container for subprojects. This top level project does not have issues (Issue tracking is not enabled in the project settings).

I am trying to figure out a way for the Python api to detect this. Right now, when my code (which is scanning for issue counts) is going through the projects, it gets to this one and errors out.

redminelib.exceptions.ForbiddenError: Requested resource is forbidden

What project property can I use to determine if the Issues are enabled? I tried project.issues._total_count but that always seems to evaluate to "None" for all projects (even ones with issues). I think that gets filled in later when you run an issue query. But I cannot run an issue query without failing and exiting the script.

I just want to have some logic to skip over these Issue disabled projects.

redmine = Redmine('https://redmine.server/redmine', key='1234567890987654321', requests={'verify': False})

projects = redmine.project.all()

for project in projects:
    issues = redmine.issue.filter(project_id=project.identifier, status_id='*')
    issueCount = 0
    for issue in issues:
        issueCount = issueCount + 1
    print( 'Project ' + project.identifier + ' has ' + str(issueCount) + ' issues' )

>Solution :

How about

try:
    # code assuming issues are enabled
except redminelib.exceptions.ForbiddenError:
    # code to execute for projects where issues are disabled

Leave a Reply