What is HTTP 415 Error? (Unsupported Media Type)

Scrapfly - Oct 24 - - Dev Community

What is HTTP 415 Error? (Unsupported Media Type)

Encountering an HTTP error can disrupt your web scraping or automation tasks, and HTTP error 415 is one such issue that indicates a problem with the type of data being sent.

In this article, we’ll explore what HTTP 415 is, the common causes behind it, how to replicate it, and whether it could be used as a blocking mechanism.

What is HTTP Error 415?

HTTP error 415 Unsupported Media Type, occurs when the server refuses to process a request because the format or media type of the data being sent is not supported. For example, if you try to send JSON data to an endpoint that only accepts XML, you would encounter a 415 error.

What are HTTP 415 Error Causes?

The most common cause of a 415 error is sending data in an unsupported format. This can happen when the Content-Type header in the request does not match the media type that the server expects.

For instance, if you're sending a POST request with application/xml but the server expects application/json, you’ll trigger a 415 error.

Practical Example

Let's explore how to configure headers, specifically Content-Type headers, in common tools like python's httpx library, and cURL.

import httpx

url = "https://httpbin.dev/json"
headers = {
    "Content-Type": "application/json",
}

response = httpx.post(url, headers=headers)
print(response.status_code)
print(response.text)
Enter fullscreen mode Exit fullscreen mode
curl -X "POST" -H "Content-Type: application/json" https://httpbin.dev/json
Enter fullscreen mode Exit fullscreen mode

In the examples above, the client is specifying that the body content is in application/json format. If the server expects a different media-type than the one that the client specified, a 415 error might occur.

To avoid 415 errors, ensure that your Content-Type header is set appropriately for the endpoint your are sending data to.

415 in Web Scraping

Http status 415 in web scraping is usually encountered when scraping POST or PUT type endpoints like search queries or form submissions. For these cases it's important to set the correct Content-Type header that not only matches the sent content type but the type server expects. To verify what content type the server expects, you can use Browser Developer Tools and inspect browser requests.

Another posibility is that the server is blocking your scraper requests and returns status code 415 purposefully to block your scraper. This is quite rare but here are some indicators that http code 415 is a block:

  • 415 is returned on GET or HEAD requests
  • 415 error cannot be replicated for the same identical requests

If you suspect that you are being blocked take a look at our guide on web scraping blocking or try Scrapfly Web Scraping API.

Power Up with Scrapfly

ScrapFly provides web scraping, screenshot, and extraction APIs for data collection at scale.

What is HTTP 415 Error? (Unsupported Media Type)

It takes Scrapfly several full-time engineers to maintain this system, so you don't have to!

Summary

HTTP 415 errors occur when the data format or media type is not supported by the server. While this error usually results from incorrect content types, it’s important to consider the possibility of blocking. With Scrapfly’s advanced scraping tools and IP rotation, you can bypass such blocks and continue scraping without interruptions.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player