Hi Team,
I'm trying to create a project using a python script and the requests library.
When doing get requests, I have no problem, but when doing post requests, I encounter a "xsrf check failed"
Here's the snippet:
payload = {"key":"EQSS_TST", "name":"qtm_test"}
r = requests.post('http://server.co.uk:7990/rest/api/1.0/projects', params=payload, auth=(user,password))
The error message is "XSRF check failed"
Thanks for you help!
Jeremie
The POST request header must contain Content-type = application/json
I've had a similar issue with posting comments through response.post(), and it solved with adding the following lines to the header:
'x-atlassian-token': 'no-check',
'x-requested-with': 'XMLHttpRequest',
So the session object looks as follows:
s = requests.Session()
s.auth = auth
s.verify = False
s.headers = {
'origin': 'https://myserver.example.net',
'pragma': 'no-cache',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 YaBrowser/18.3.1.1220 Yowser/2.5 Safari/537.36',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'referer': 'https://myserver.example.net/instance_name/pages/viewpage.action?pageId=123456789',
'x-atlassian-token': 'no-check',
'x-requested-with': 'XMLHttpRequest',
}
and response object looks as:
r = s.post(
'{}'.format(WEB),
params = params,
data = data,
)
print(r.text)
where
WEB = 'https://server.example.net/instance_name/pages/viewpage.action?pageId=123456789'
params = {'actions':'true'}
data = {
'html': '<p>Test</p>',
'watch': 'false',
'uuid': '54b022eb-e098-a3ad-5f8d-fd68619681fb'
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not planning on adding an avatar to the project so I shouldn't need to define the content-type.
The example prototype on the documentation says:
{
"key": "PRJ",
"name": "My Cool Project",
"description": "The description for my cool project.",
"avatar": "data:image/png;base64,<base64-encoded-image-data>"
}
Has anybody ever created a project using the "requests" python library?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.