How to fix "request failed with status code: 415" error while creating Azure custom text classification Project using Azure AI Language REST API?

Sriram Reddy Gade 51 Reputation points
2024-01-22T09:53:49.06+00:00

Hello, I am attempting to create a custom text classification project using Azure AI Language resource REST API, but I am encountering a "request failed with status code: 415" error. I followed the steps outlined in this Microsoft Learn article: https://learn.microsoft.com/en-us/azure/ai-services/language-service/custom-text-classification/how-to/create-project?tabs=azure-portal%2Capis%2Cmulti-classification. I have already assigned the 'Storage Blob Data Owner' role to the language resource in storage account. Here's the code that I am having trouble with:

import requests

url = "<language resource endpoint>/language/authoring/analyze-text/projects/myProject?api-version=2022-05-01"

headers = {
    "Ocp-Apim-Subscription-Key": "<language resource key>",
    "Content-Type":"application/json"

	
}

body = {
  "projectName": "myProject",
  "language": "en-us",
  "projectKind": "customMultiLabelClassification",
  "description": "Project description",
  "multilingual": "True",
  "storageInputContainerName":"<Container Name>"
}

response = requests.patch(url=url, headers=headers, json=body)

I am getting an error "request failed with status code: 415" as output. Would someone be able to provide some guidance on how to fix this error? Thank you.

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
358 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,393 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 15,676 Reputation points
    2024-01-22T11:09:43.1+00:00

    The error code you are receiving is common and it is related to an unsupported meedia type issue. This means that the server is refusing to accept the request because the payload format is in an unsupported format. The most common cause of a 415 error is an incorrect Content-Type header. Ensure that your Content-Type header matches the expected format for the API. In most cases, it should be application/json Try to add header "Accept" :

    Accept: application/json