问题描述
我是Python的新手,是jira-python库的新手,还是网络编程的新手,尽管我在应用程序和集成编程以及数据库查询方面确实有很多经验(尽管已经有一段时间了). /p>
使用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})
到
self._session = requests.session()
我不知道自己到底在做什么,但是在更改之前我遇到了一个错误,在更改之后我得到了成功返回的项目名称列表.
然后,我尝试了基本身份验证,以便可以利用我的Jira权限并进行报告.最初也失败了.我对
进行了相同的更改def _create_http_basic_session
中的
,但是现在我又遇到了另一个错误.所以问题没有解决.现在我得到了另一个错误:
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).
因此,我决定仅使用请求模块进行一次超级简单的测试,我相信jira-python模块正在使用该模块,并且该代码似乎使我登录.我得到了很好的答复:
import requests r = requests.get(the_url, auth=(my username , password)) print r.text
有什么建议吗?
这是我使用 jira 的方式带有Python脚本中的身份验证的模块:
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
I'm new to Python, new to the jira-python library, and new to network programming, though I do have quite a bit of experience with application and integration programming and database queries (though it's been a while).
Using Python 2.7 and requests 1.0.3
I'm trying to use this library - http://jira-python.readthedocs.org/en/latest/ to query Jira 5.1 using Python. I successfully connected using an unauthenticated query, though I had to make a change to a line in client.py, changing
I changed
self._session = requests.session(verify=verify, hooks={'args': self._add_content_type})
to
self._session = requests.session()
I didn't know what I was doing exactly but before the change I got an error and after the change I got a successful list of project names returned.
Then I tried basic authentication so I can take advantage of my Jira permissions and do reporting. That failed initially too. And I made the same change to
def _create_http_basic_session
in client.py , but now I just get another error. So problem not solved. Now I get a different error:
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).
So then I decided to do a super simple test just using the requests module, which I believe is being used by the jira-python module and this code seemed to log me in. I got a good response:
import requests r = requests.get(the_url, auth=(my username , password)) print r.text
Any suggestions?
Here's how I use the jira module with authentication in a Python script:
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
这篇关于使用Jira-Python进行基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!