带有python的Jira API在有效凭据上返回错误401

问题描述 投票:1回答:2

我正在尝试使用Jira python库来做一些非常基本的事情。甚至在做任何事情之前,构造函数都会失败。

address = 'https://myaddress.atlassian.net'
options = {'server': address}
un = 'my@user.com'
#un = 'my' #also doesn't work
pw = 'the_pasSword!'
cookie = (un, pw)

j = JIRA(options, basic_auth=cookie)

这是所有代码。

最后一行失败了

警告:root:从GET https://myaddress.atlassian.net/rest/api/2/serverInfo获得可恢复的错误,将在13.906688704524315s重试[1/3]。呃:401

警告:root:从GET https://myaddress.atlassian.net/rest/api/2/serverInfo获得可恢复的错误,将在4.071181495745648s中重试[2/3]。呃:401

警告:root:从GET https://myaddress.atlassian.net/rest/api/2/serverInfo获得可恢复的错误,将在6.266303262421157s中重试[3/3]。呃:401

在atlassian上手动尝试凭据可以正常工作,我可以登录。

知道为什么这种非常简单的连接尝试不起作用?

python rest jira jira-rest-api
2个回答
2
投票

他们一直在讨论在基本身份验证中弃用密码。尝试生成API令牌并使用它来代替您的密码。

https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/

address = 'https://myaddress.atlassian.net'
options = {'server': address}
un = 'my@user.com'
#un = 'my' #also doesn't work
token = 'the_tokEn'
cookie = (un, token)

j = JIRA(options, basic_auth=cookie)

0
投票

请尝试以下代码:

from jira.client import JIRA
import logging
import getpass
import datetime
import os

# Clearing the screen
os.system('cls||clear')
# Getting user authentication data
print 'Please enter your authentication data'
USER = raw_input('Username: ')
PASSWORD = getpass.getpass('Password: ')
print
JIRA_URL = "YOUR_JIRA_URL"
i = datetime.datetime.now()
TODAY = ("%s/%s/%s" % (i.day, i.month, i.year) )

def connect_jira(log, jira_server, jira_user, jira_password):
    '''
    Connects to JIRA

    Returns None on error
    '''
    try:
        log.info("Connecting to JIRA: %s" % jira_server)
        jira_options = {'server': jira_server}
        jira = JIRA(options=jira_options, basic_auth=(jira_user, jira_password))
                                        # ^--- Note the tuple
        return jira
    except Exception,e:
        log.error("Failed to connect to JIRA: %s" % e)
        return e

# Creating logger
log = logging.getLogger(__name__)
# Creating a Jira connection object, jc
jc = connect_jira(log, JIRA_URL, USER, PASSWORD)
© www.soinside.com 2019 - 2024. All rights reserved.