Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSON bad request Unrecognized token

when trying to post via the youtrack api (adding a issue) I get a problematic error.

Here is my code:

`postHeaders = {
    'Accept':'application/json',
    'Authorization':'secret',
    'Content-Type':'application/json'
    
}

postData = {
    'project':{'id':'0-5'},
    'summary':'sample',
    'description':'Sample description'
}


responsePost = requests.post("https://yourcompany.youtrack.cloud/api/issues", headers=postHeaders, data=postData)
print(responsePost.content)`

I got this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

b'{"error":"bad_request","error_description":"Unrecognized token \'project\': was expecting (JSON String, Number, Array, Object or token \'null\', \'true\' or \'false\')\\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 9]"}'

Can You guys help.

I tried formatting in various ways JSON format I changed ‘ to ‘ but nothing would work. the result is to add a issue to the project with id 0-5

>Solution :

Maybe this dumping to json will support?

import json

postData = {
    'project': {'id': '0-5'},
    'summary': 'sample',
    'description': 'Sample description'
}

# Convert the dictionary to a JSON string
postData_json = json.dumps(postData)

print(postData_json)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading