-->

Welcome to our Coding with python Page!!! hier you find various code with PHP, Python, AI, Cyber, etc ... Electricity, Energy, Nuclear Power

Sunday 23 June 2019

What server to use to connect python with jira api

I have ran across this when I have special characters in my password and it doesn't get parsed well in the script.
Try
from jira import JIRA
import getpass

password = getpass.getpass()

options = {'server': 'url'}
jira = JIRA(options, basic_auth=('username', password))


If somebody still need a solution, you can install JIRA rest api lib https://pypi.python.org/pypi/jira/. Just a simple example :
from jira.client import JIRA

jira_server = "http://yourjiraserver.com"
jira_user = "login"
jira_password = "pass"

jira_server = {'server': jira_server}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))

group = jira.group_members("jira-users")
for users in group:
    print users


import urllib2, base64
import requests
import ssl
import json
import os
from pprint import pprint
import getpass

UserName = raw_input("Ener UserName: ")
pswd = getpass.getpass('Password:')

# Total number of users or licenses used in JIRA. REST api of jira can take values of 50 incremental
ListStartAt = [0,50,100,150,200,250,300]
counter = 0
for i in ListStartAt:
    request = urllib2.Request("https://jiraserver.com/rest/api/2/group/member?groupname=GROUPNAME&startAt=%s" %i)

    base64string = base64.encodestring('%s:%s' % (UserName, pswd)).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string) 
    gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
    result = urllib2.urlopen(request, context=gcontext)

    JsonGroupdata = result.read()
    jsonToPython = json.loads(JsonGroupdata)

    try:
        for i in range (0,50):
            print jsonToPython["values"][i]["key"]
            counter = counter+1
    except Exception as e:
        pass
print counter

No comments:

Post a Comment

Thanks for your comments

Rank

seo