检查是否存在s3网址

Dav*_*542 3 python http boto

我有以下网址,它存在:

https://s3-us-west-1.amazonaws.com/premiere-avails/458ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg
Run Code Online (Sandbox Code Playgroud)

但是这个没有:

https://s3-us-west-1.amazonaws.com/premiere-avails/459ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg
Run Code Online (Sandbox Code Playgroud)

有没有办法检查一个网址,看看它是否有效,没有下载文件(它可能是1GB文件)?请注意,我不想用来boto查看密钥是否存在,我想使用HTTP请求.

ely*_*ase 7

试试这个:

import httplib
from urlparse import urlparse

def url_exists(url):
    _, host, path, _, _, _ = urlparse(url)
    conn = httplib.HTTPConnection(host)
    conn.request('HEAD', path)
    return conn.getresponse().status < 400
Run Code Online (Sandbox Code Playgroud)