1

I'm trying to fetch all issues in JIRA for all projects. When doing the call one at a time, it works perfect. When trying to run it in a for loop I'm prompted with a 400 Client error.

The way that works:

results = jira_instance.jql("project = FJA", limit = 100, fields=["issuetype", "status", "summary"])

The way that does not work:

projects = ["ADV", "WS", "FJA", "FOIJ", "QW", "UOI"]

for key in projects:
  results = jira_instance.jql(f"project = {key})", limit = 100, fields=["issuetype", "status", "summary"])

The error:

Traceback (most recent call last):
  File "C:\jira-api-python\jira.py", line 24, in <module>
    results = jira_instance.jql("project = {key}", limit = 100, fields=["issuetype", "status", "summary"])
  File "C:\.virtualenvs\jira-api-python-rouJrYa4\lib\site-packages\atlassian\jira.py", line 2271, in jql
    return self.get("rest/api/2/search", params=params)
  File "C:\.virtualenvs\jira-api-python-rouJrYa4\lib\site-packages\atlassian\rest_client.py", line 264, in get
    response = self.request(
  File "C:\.virtualenvs\jira-api-python-rouJrYa4\lib\site-packages\atlassian\rest_client.py", line 236, in request
    response.raise_for_status()
  File "C:\.virtualenvs\jira-api-python-rouJrYa4\lib\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://stuff.atlassian.net/rest/api/2/search?startAt=0&maxResults=100&fields=issuetype%2Cstatus%2Csummary&jql=project+%3D+%7Bkey%7D

My guess is that I'm not using the f-string correct. But when I print the value of {key} it is correct.

Any pointers would be greatly appreciated.

Thank you for your time.

Edit:

Added the full traceback, only removed the path to my machine and changed the URL to the endpoint. Below is the full file with credentials and endpoint redacted. The ideas is to create a csv for each project.

The full code:

from atlassian import Jira
import pandas as pd
import time

jira_instance = Jira(
    url = "https://stuff.atlassian.net/",
    username = "user",
    password = "pass",
)



projects = ["ADV", "WS", "FJA", "FOIJ", "QW", "UOI"]
FIELDS_OF_INTEREST = ["key", "fields.summary", "fields.status.name"]
timestamp = time.strftime("%Y%m%d-%H%M%S")
file_ending = ".csv"

for key in projects:


    print(f"stuff = {key}")
    results = jira_instance.jql(f"project = {key})", limit = 1000, fields=["issuetype", "status", "summary"])
Berimbolinho
  • 465
  • 1
  • 6
  • 16
  • 1
    Look at the code in the code snippet you posted. Look at the code in your error message. That's not the same code. – user2357112 Apr 22 '21 at 08:47
  • This part in your error message doesnt have the `f` so its just a plain old string. so you dont actually insert the key `results = jira_instance.jql("project = {key}",` so you will just be sending this is a literal string – Chris Doyle Apr 22 '21 at 08:48
  • If you retyped your code by hand for this question, well, here's a demonstration of why not to do that. You end up changing crucial bits and obscuring the problem. Always copy-paste from a file you actually ran. – user2357112 Apr 22 '21 at 08:50
  • Are you sure you're looking at the right file? Your "full" code still says `f"project = {key})"`, but your error message says `"project = {key}"`. – user2357112 Apr 22 '21 at 09:07
  • I'm not certain. I'm fairly new to this and as such I'm asking here. If i run `print(f"stuff = {key}") I get the response I want, which is the value in the projects list. – Berimbolinho Apr 22 '21 at 09:09

1 Answers1

0

I found the very simple solution.

In this snippet: results = jira_instance.jql(f"project = {key})", limit = 1000, fields=["issuetype", "status", "summary"])

The ) after {key} was not supposed to be there.

Thank you for the help

Berimbolinho
  • 465
  • 1
  • 6
  • 16