Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python request library post function returning u"Unrecognized token 'filspoetfed': was expecting null"

I have no idea what the error this command (the request line) throws means and there doesn't seem to be any information online about it.

 data = {
....:        'fields':
....:            {
....:            'environment': '- \\n- Repeated : 0 times',
....:            'description': '',
....:            'summary': 'Fill in Something',
....:            'project': {
....:                        "key": "QABL"
....:                 },
....:            'assignee': 'qa-auto',
....:            'issuetype': 'Bug',
....:            'priority': 'Major'
....:            }
....:        }

print header
{'content-type': 'application/json'}

r = requests.post("https://jira.some-company.net/rest/api/latest/issue/", headers=header, auth=requests.auth.HTTPDigestAuth('user', 'password'), data=data)

 r.json()

I tried to do a post request to JIRA using the request library, and the JSON response to r.json() looks like this...

 {u'errorMessages': 
    [u"Unrecognized token 'filspoetfed': was expecting 'null', 'true', 'false' or NaN\n 
    at [Source: org.apache.catalina.connector.CoyoteInputStream@10758d77; line: 1, column: 23]"]}

Anybody seen this before? There is no attribute 'filspoetfed' in my JIRA issue/JSON, so I don't understand. The only other possibility to my knowledge is that it is getting transferred into unicode when it gets submitted...but if that is the problem I don't know how to get around it. I did this in the same format as on the JIRA REST api page. Help would be greatly appreciated!

like image 553
Ian Avatar asked Jun 25 '15 17:06

Ian


1 Answers

I had a similar issue and solved it by changing the request

requests.post(url, data = json.dumps(data),auth=HTTPBasicAuth(username, password), headers= header)

The important thing is to use json.dumps(data) instead of data and in the header also included

'Accept': 'application/json'

Hope it works for you! Have a nice day

like image 111
Fernando Martinez Avila Avatar answered Nov 03 '22 07:11

Fernando Martinez Avila