How to Use HEAD Requests in Python 2 to Determine MIME Type Without Downloading Content?

Linda Hamilton
Release: 2024-11-05 03:05:02
Original
256 people have browsed it

How to Use HEAD Requests in Python 2 to Determine MIME Type Without Downloading Content?

HEAD HTTP Requests in Python 2: Retrieving Headers for MIME Type Determination

Question:

To determine the MIME type of a URL without downloading the content, how can a HEAD request be sent in Python 2?

Answer:

urllib2 offers a convenient approach to execute HEAD requests. It simplifies the process by parsing the URL, eliminating the need to manually split it into host name and path:

The headers can be accessed through response.info(). Additionally, you can retrieve the redirected URL using response.geturl():

The above is the detailed content of How to Use HEAD Requests in Python 2 to Determine MIME Type Without Downloading Content?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template