python JIRA connection with proxy

狂风中的少年 提交于 2019-12-10 17:48:12

问题


I'm trying to connect via python-jira using a proxy:

server = {"server": "https://ip:port/jira",
          'proxies': {"http": "http://ip:port", "https": "http://ip:port"},
          'verify': False,
          'stream': True}

cls.jira_object = JIRA(options=server,
                       basic_auth=(user, password),
                       validate=True)

Traceback error:

tests\jira_test\ticket_test.py:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build\bdist.win-amd64\egg\jira\client.py:217: in __init__
    ???
build\bdist.win-amd64\egg\jira\client.py:1841: in session
    ???
build\bdist.win-amd64\egg\jira\utils.py:78: in json_loads
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

r = None, verb = '???', kwargs = {}, request = None, headers = None

>   ???
E   JIRAError: JiraError HTTP None

Any idea how to allow jira-python to connect with proxy?


回答1:


You can provide the proxy to the constructor of JIRA:

cls.jira_object = JIRA(options=server,
                       basic_auth=(user, password),
                       validate=True,
                       proxies={"http": "http://ip:port", "https": "http://ip:port"})

Remember to remove the "proxies" from your options dict

More info about the constructor: https://github.com/pycontribs/jira/blob/develop/jira/client.py




回答2:


This worked for me in python3.

server =  {'server': 'https://<jira.url.com>','proxies':"http://%s:%s@<ip>:<port>"%(proxy_user,proxy_password),'verify':True}

jira_object = JIRA(options=server,basic_auth=(jira_user,jira_password),                     validate=True)

Another option :

import os
from jira import JIRA 

os.environ['https_proxy']='<proxy url>:<port>'
os.environ['http_proxy']='<proxy url>:<port>'
con = JIRA(basic_auth=(<username>,<password>),options={'server':'<jira_url>'})



回答3:


It seems like it requires bit of a magic. Have a look here at this answer.

Here's code:

my_jira = JIRA(jira_options, basic_auth=(jira_admin, jira_passwd))
my_jjira._session.proxies = {'http': '127.0.0.1:8888', 'https': '127.0.0.1:8888' }


来源:https://stackoverflow.com/questions/30872740/python-jira-connection-with-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!