【问题标题】:Using OAuth to authenticate Jira REST API through proxy server using Python使用 OAuth 通过代理服务器使用 Python 对 Jira REST API 进行身份验证
【发布时间】:2019-03-28 22:04:47
【问题描述】:

由于我公司的代理设置,无法使用 OAuth 凭据通过虚拟机连接到 JIRA Server API。

我能够使用 OAuth 进行身份验证并在本地运行我的脚本而不会出现问题。

我还在 cURL(如下)中测试了这个脚本的一个版本,它可以按预期工作,但它不符合我公司的安全标准,因为它使用的是简单的身份验证。

JIRA 文档没有提供任何有用的信息,而且我在 Atlassian 论坛或 StackOverflow 上没有找到任何解决此特定问题的解决方案。

实例化 JIRA 对象:

jira_options={'server': 'https://jira.domain.com'}

oauth_dict = {
'access_token': access_token,
'access_token_secret': access_token_secret,
'consumer_key': consumer_key,
'key_cert': key_cert_data
}

jira = JIRA(options=jira_options, oauth=oauth_dict)

这是带有简单身份验证的正常 CURL:

curl --noproxy “*” -o /usr/local/airflow/data/jira_input.json -D- -u ‘+jira_client_email+‘:’+jira_client_key+' -X GET -H “Content-Type: application/json” “https://jira.domain.com/rest/api/2/search?jql=project=CC&updatedDate=-3d&startAt=0&maxResults=3000”

我希望输出返回一个 JIRA 对象并允许我的程序访问 JIRA 的 API。

我得到的实际输出是下面的错误消息:

[2019-03-27 15:03:23,907] {bash_operator.py:94} INFO - WARNING:root:HTTPSConnectionPool(host='jira.domain.com', port=443): Max retries exceeded with url: /rest/api/2/serverInfo (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6e45ca5898>: Failed to establish a new connection: [Errno 110] Connection timed out',)) while doing GET https://jira.domain.com/rest/api/2/serverInfo [{'params': None, 'headers': {'User-Agent': 'python-requests/2.18.4', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json,*.*;q=0.9', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json', 'X-Atlassian-Token': 'no-check'}}]

【问题讨论】:

    标签: python curl proxy jira airflow


    【解决方案1】:

    如果您的本机操作系统的请求通过基于 Windows 的经过身份验证的代理,您可以在 VM 上使用 CNTLM。

    否则,请尝试在 VM 端适当地设置代理环境变量。这些将用于 python 请求 pip。

    相关变量

    • HTTP_PROXY
    • HTTPS_PROXY
    • NO_PROXY

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 2017-12-10
      • 2017-11-24
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多