【问题标题】:How to connect to JIRA api with 2fa enabled by organization?如何使用组织启用的 2fa 连接到 JIRA api?
【发布时间】:2022-10-31 02:04:39
【问题描述】:

我使用自托管的 Jira,我目前正在尝试使用我的组织启用了 2fa 的 python 脚本(和请求库)连接到 Jira api。我不是该项目的管理员,在创建个人访问令牌并将其用作承载令牌之后,我只得到了来自服务器的响应,告诉我放入 OTP 以继续。 我在考虑是否可以在向 api 发出请求时将 OTP 作为授权标头的一部分传递,但找不到任何有用的提示。我也一直在研究 OAuth 令牌,但据我了解,我无法创建一个,因为我无法在 Jira 中创建应用程序链接(因为我不是管理员)。 有谁知道我如何设法建立与 api 的连接?

任何帮助,将不胜感激!!

干杯,

丽兹

【问题讨论】:

    标签: jira jira-rest-api python-jira


    【解决方案1】:

    嘿@Liz 试试这个项目以获得灵感 - https://github.com/dren79/JiraScripting_public

    我根据 API 文档中的以下示例构建了它。

    #This code sample uses the 'requests' library:
    #http://docs.python-requests.org
    import requests
    from requests.auth import HTTPBasicAuth
    import json
    
    url = "https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}"
    
    auth = HTTPBasicAuth("email@example.com", "<api_token>")
    
    headers = {
       "Accept": "application/json"
    }
    
    response = requests.request(
       "GET",
       url,
       headers=headers,
       auth=auth
    )
    
    print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      • 2016-02-27
      • 2022-10-31
      • 2018-06-24
      • 1970-01-01
      • 2018-10-29
      • 2019-09-07
      相关资源
      最近更新 更多