requests.post with Authentication giving error 415 for jira rest api in python

R.Ram
url = "https://example.com/jira/rest/api/2/issue/issue_key/comment"
data = json.dumps({"body": 'some string'})
headers = {'content-type':'application/json'}
r = requests.post(url, data, auth=('username', 'password'))

--> r.status_code output is 415.

But in case of

r = requests.get(url, data, auth=('username', 'password'))

--> r.status_code output is 200. Please help me to identify issue.

JustOneQuestion

you forgot to add the headers variable to your post requests. thats why it fails. just add this to your post request and you should get a 201 status code as response:

r = requests.post(url, data, auth=('username', 'password'), headers=headers)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error code 415 when forwarding a POST from an api to another

POST to Jersey REST service getting error 415 Unsupported Media Type

415 error while calling post API from jersey client

Ajax request to Spring REST api 415 error

Uploading attachments to Confluence REST API with Python Requests gives 415 and 500 Errors

python requests POST 400 error

Livy REST API: GET requests work but POST requests fail with '401 Authentication required'

Django-rest-framework with django OAuth 2.0 giving authentication error

Python requests 422 error on post

Python Requests + Marketo REST API

Atlassian Connect-Express: JIRA REST API authentication within the JIRA plugin

JIRA Cloud REST API : Forbidden (403) error

WP REST API not required authentication on POST

Jira POST & PUT Rest Calls return Error 400 from Python

python requests: PUT request to azure fails with 415 error

How to send POST request to JIRA for creating a Project through REST api

JIRA REST API - Basic Authentication

python authentication with requests library via POST

Jira API not giving expected response

Authentication for POST REST API with spring restTemplate

Rest API programming: Requests vs urllib2 in Python 2.7 -- the API needs authentication (Error 401)

JIRA Cloud REST API (OAuth 2.0) Error 403 on POST Requests

requests.post is not giving any response in python?

Error to post the data in python requests

Cookie authentication error using Python requests

POST with Jax-RS giving HTTP error code 415?

angular http post error 415 .net core web api

Issue with POST request with API oauth2 / return: error 415

Using Python Requests to POST data to REST API