使用jira-python进行基本身份验证

Nea*_*din 4 python jira

我是新来的Python,新来的JIRA-Python库,以及新的网络编程,但我确实有相当多的与应用和集成编程和数据库查询的经验(尽管它已经有一段时间).

使用Python 2.7并请求1.0.3

我正在尝试使用这个库 - http://jira-python.readthedocs.org/en/latest/来使用Python查询Jira 5.1.我使用未经身份验证的查询成功连接,但我必须更改一行client.py,更改

我变了

self._session = requests.session(verify=verify, hooks={'args': self._add_content_type}) 
Run Code Online (Sandbox Code Playgroud)

self._session = requests.session() 
Run Code Online (Sandbox Code Playgroud)

我不知道我在做什么,但在更改之前我收到了一个错误,在更改之后我得到了一个成功的项目名称列表返回.

然后我尝试了基本身份验证,以便我可以利用我的Jira权限并进行报告.最初也失败了.我做了同样的改变

def _create_http_basic_session
Run Code Online (Sandbox Code Playgroud)

client.py,但现在我只是得到另一个错误.所以问题没有解决.现在我得到一个不同的错误:

HTTP Status 415 - Unsupported Media Type
type Status report
message Unsupported Media Type

description The server refused this request because the request entity is in
a format not` `supported by the requested resource for the requested method 
(Unsupported Media Type).
Run Code Online (Sandbox Code Playgroud)

.于是我决定做一个超级简单的测试只使用请求模块,我相信这是正在使用JIRA的Python模块,并且该代码似乎在登录我我得到了良好的反响:

import requests

r = requests.get(the_url, auth=(my username , password))
print r.text
Run Code Online (Sandbox Code Playgroud)

有什么建议?

mdo*_*oar 13

以下是我在Python脚本中使用jira模块进行身份验证的方法:

from jira.client import JIRA
import logging

# Defines a function for connecting to Jira
def connect_jira(log, jira_server, jira_user, jira_password):
    '''
    Connect to JIRA. Return 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 None

# create logger
log = logging.getLogger(__name__)

# NOTE: You put your login details in the function call connect_jira(..) below!

# create a connection object, jc
jc = connect_jira(log, "https://myjira.mydom.com", "myusername", "mypassword")

# print names of all projects
projects = jc.projects()
for v in projects:
       print v
Run Code Online (Sandbox Code Playgroud)


小智 6

下面的Python脚本连接到Jira并进行基本身份验证并列出所有项目。

from jira.client import JIRA
options = {'server': 'Jira-URL'}
jira = JIRA(options, basic_auth=('username', 'password'))
projects = jira.projects()
for v in projects:
   print v
Run Code Online (Sandbox Code Playgroud)

它会打印您的Jira实例中所有可用项目的列表。