Python 中的 f-string 与 atlassian-python 包。给出错误的请求

f-string in Python with the atlassian-python package. Gives bad request

我正在尝试获取 JIRA 中所有项目的所有问题。一次接一个电话,效果很好。在 for 循环中尝试 运行 它时,系统提示我出现 400 客户端错误。

工作方式:

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

行不通的方法:

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

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

错误:

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

我的猜测是我没有正确使用 f 弦。但是当我打印 {key} 的值时它是正确的。

任何指点将不胜感激。

感谢您的宝贵时间。

编辑:

添加了完整的回溯,只删除了我机器的路径并将 URL 更改为端点。下面是完整的文件,其中包含已编辑的凭据和端点。想法是为每个项目创建一个 csv。

完整代码:

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"])

我找到了非常简单的解决方案。

在此代码段中: results = jira_instance.jql(f"project = {key})", limit = 1000, fields=["issuetype", "status", "summary"])

{key} 之后的 ) 不应该在那里。

感谢您的帮助