Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

XSRF error create project using jira-python

thierry mallard January 29, 2014

Hi,

Please find a python script to list issues and to create project to a JIRA database.

# 
# 

from jira.client import JIRA

from jira.exceptions import JIRAError

user     = 'admin'
password = 'admin'
server   = 'http://10.5.123.121:8080'
jira = JIRA(basic_auth=(user, password), options={'server': server})    # a username/password tuple

# Get the mutable application properties for this server (requires jira-system-administrators permission)
props = jira.application_properties()

# Find all issues reported by the admin
issues = jira.search_issues('assignee=admin')

print "issues " + "(" + str(len(issues)) + "):" + str(issues)

projname       ="ProjetCreatedFromPython"
projkey        ="PROJPYTHON"
projassignee   =user

try:
        proj = jira.project(projkey)
except JIRAError:
   print "Create " + projname + "(" + projkey + ")"
   jira.create_project(projkey, projname, projassignee)

This gives the following output

ERROR:root:Unexpected result while running create project. Server response saved in d:\donnees\u00p3038\appdata\local\temp\python-jira-error-create-project-dkgnla.html for further investigation [HTTP response=200].
issues (6):[<JIRA Issue: key=u'TST-8', id=u'10602'>, <JIRA Issue: key=u'TST-7', id=u'10601'>, <JIRA Issue: key=u'TST-6', id=u'10600'>, <JIRA Issue: key=u'TST-4', id=u'10502'>, <JIRA Issue: key=u'TST-3', id=u'10501'>, <JIRA Issue: key=u'TST-2', id=u'10500'>]
Create ProjetCreatedFromPython(PROJPYTHON)

Listing issues works fine.

But creating a project fails with the error " Missing XSRF security token"

JIRA database is accessible through browser but I need to access via jira-python to automate project configuration.

Any hint?

Thanks in advance.

Thierry

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Tiago Comasseto
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2014

Hi Thierry,

You can disable XSRF token in order to avoid problems as the one you're seeing. This can be done following these steps:

  1. Add the line jira.xsrf.enabled=false into the jira-config.properties file;
    In new JIRA installations, this file may not initially exist and if so, needs to be created manually.
  2. Restart JIRA;
  3. Double check the system info and verify that the property is pick up by JIRA.

I hope it helps.

Cheers

Sorin Sbarnea (Citrix)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 15, 2014

This doesn't work for ON DEMAND, see https://jira.atlassian.com/browse/JRA-39153Any other workarounds?

0 votes
john doe February 9, 2014

Question is closed.

Thks

0 votes
thierry mallard February 9, 2014

Question is closed

Thks

0 votes
thierry mallard February 3, 2014

Thks Tiago.

This helps to go further.

But next error is "Administrator access", and project cannot be created.

But using same id, it works from a browser.

Is there anything in particular to configure to be able to create project from python?

Thks

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events