Skip to main content
Added allow_redirects=True
Source Link
Kalob Taulien
  • 1.9k
  • 17
  • 23

For anyone using Python 3 and looking for a quick solution using the requests package:

import requests 
response = requests.head( 
    "https://website.com/yourfile.mp4"),  # Example file 
    allow_redirects=True
)
print(response.headers['Content-Length']) 

Note: Not all responses will have a Content-Length so your application will want to check to see if it exists.

if 'Content-Length' in response.headers:
    ... # Do your stuff here 

For anyone using Python 3 and looking for a quick solution using the requests package:

import requests 
response = requests.head("https://website.com/yourfile.mp4") # Example file 
print(response.headers['Content-Length']) 

Note: Not all responses will have a Content-Length so your application will want to check to see if it exists.

if 'Content-Length' in response.headers:
    ... # Do your stuff here 

For anyone using Python 3 and looking for a quick solution using the requests package:

import requests 
response = requests.head( 
    "https://website.com/yourfile.mp4",  # Example file 
    allow_redirects=True
)
print(response.headers['Content-Length']) 

Note: Not all responses will have a Content-Length so your application will want to check to see if it exists.

if 'Content-Length' in response.headers:
    ... # Do your stuff here 
Source Link
Kalob Taulien
  • 1.9k
  • 17
  • 23

For anyone using Python 3 and looking for a quick solution using the requests package:

import requests 
response = requests.head("https://website.com/yourfile.mp4") # Example file 
print(response.headers['Content-Length']) 

Note: Not all responses will have a Content-Length so your application will want to check to see if it exists.

if 'Content-Length' in response.headers:
    ... # Do your stuff here