What is MIME type "application/x-httpd-python"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

application/x-httpd-python is a MIME type that tells the server to run Python code. It is used to execute scripts on the web server instead of simply sending file data.
This type is tied to Python web handling, especially in environments using Apache with mod_python. It lets the server process PY files to generate dynamic content.
Files bearing the PY extension use this MIME type. Although its use was more common with mod_python, modern environments may prefer other methods like WSGI.
Learn more about this setup in the details on mod_python on Wikipedia.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: application/x-httpd-python    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="application/x-httpd-python">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'application/x-httpd-python');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

What is the purpose of application/x-httpd-python?

This MIME type instructs the web server to execute the file as a Python script server-side rather than sending it to the client as text. It is primarily associated with the Apache module mod_python, allowing .py files to generate dynamic web content.

How do I configure Apache to use application/x-httpd-python?

To enable this, you must have mod_python installed and add a handler directive to your configuration. Typically, you would add AddHandler application/x-httpd-python .py to your httpd.conf or .htaccess file to ensure the server processes the scripts.

Why is my browser downloading the .py file instead of running it?

If the browser downloads the file, the server is likely missing the application/x-httpd-python handler configuration. This means the server treats the file as static content rather than an executable script, which can expose your source code to the public.

Is application/x-httpd-python used for modern Python web development?

Generally, no. While valid, this MIME type is tied to mod_python, which has largely been superseded by the WSGI standard (Web Server Gateway Interface). Modern frameworks like Django or Flask typically use mod_wsgi or application servers like Gunicorn instead.

What is the difference between application/x-httpd-python and text/x-python?

application/x-httpd-python tells the server to run the code, while text/x-python identifies the content as Python source code intended to be read or edited. Mislabeling these can lead to security issues where code is displayed instead of executed.

Does Nginx support application/x-httpd-python?

Nginx does not natively support mod_python or this specific MIME handler in the same way Apache does. To run Python applications with Nginx, you should configure a reverse proxy to pass requests to a WSGI server (like uWSGI) rather than relying on this MIME type.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.