<gh_stars>0
from json import dumps
import requests
from requests.auth import HTTPBasicAuth

username = 'YOUR_USERNAME'
password = '<PASSWORD>'

issueProjectKey = "PROJECTKEY"
issueSummary = "Create Issue with requests"
issueDescription = "Login and Issue creation test requests"
issueTypeName = "Test"

projectURL = 'JIRA_SERVER/jira'
createIssueURL = projectURL + "/rest/api/2/issue/"
s = requests.Session()
headers = {"Content-Type": "application/json"}
print "Creating Issue ..."

values = dumps({
    "fields": {
        "project": {
            "key": issueProjectKey
        },
        "summary": issueSummary,
        "description": issueDescription,
        "issuetype": {
            "name": issueTypeName
        },
        "labels": [
            "testCreateLabel"
        ],
        "priority": {
            "name": "Minor"
        },
        "assignee": {
            "name": username
        }
    }
})


try:
    r = s.post(createIssueURL, data=values, headers=headers, auth=HTTPBasicAuth(username,password), verify=False)
    print r.status_code
    contentObject = r.json()
    print contentObject['key']
except requests.exceptions.HTTPError as error:
    print error



from json import dumps
import requests
from requests.auth import HTTPBasicAuth

username = 'YOUR_USERNAME'
password = '<PASSWORD>'

issueProjectKey = "PROJECTKEY"
issueSummary = "Create Issue with requests"
issueDescription = "Login and Issue creation test requests"
issueTypeName = "Test"

projectURL = 'JIRA_SERVER/jira'
createIssueURL = projectURL + "/rest/api/2/issue/"
s = requests.Session()
headers = {"Content-Type": "application/json"}
print "Creating Issue ..."

values = dumps({
    "fields": {
        "project": {
            "key": issueProjectKey
        },
        "summary": issueSummary,
        "description": issueDescription,
        "issuetype": {
            "name": issueTypeName
        },
        "labels": [
            "testCreateLabel"
        ],
        "priority": {
            "name": "Minor"
        },
        "assignee": {
            "name": username
        }
    }
})


try:
    r = s.post(createIssueURL, data=values, headers=headers, auth=HTTPBasicAuth(username,password), verify=False)
    print r.status_code
    contentObject = r.json()
    print contentObject['key']
except requests.exceptions.HTTPError as error:
    print error