Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 检查是否存在S3URL_Python_Http_Boto - Fatal编程技术网

Python 检查是否存在S3URL

Python 检查是否存在S3URL,python,http,boto,Python,Http,Boto,我有以下url,该url已存在: https://s3-us-west-1.amazonaws.com/premiere-avails/458ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg 但这一条没有: https://s3-us-west-1.amazonaws.com/premiere-avails/459ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg 有没有办法在不下载文件(可能是

我有以下url,该url已存在:

https://s3-us-west-1.amazonaws.com/premiere-avails/458ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg
但这一条没有:

https://s3-us-west-1.amazonaws.com/premiere-avails/459ca3ce-c51e-4f69-8950-7af3e44f0a3d__chapter025.jpg
有没有办法在不下载文件(可能是1GB文件)的情况下检查url是否有效?请注意,我不想使用
boto
查看密钥是否存在,我希望使用
HTTP
请求。

尝试以下操作:

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
导入httplib
从URLPRASE导入URLPRASE
def url_存在(url):
_,主机,路径,,,=url解析(url)
conn=httplib.HTTPConnection(主机)
连接请求(“头”,路径)
返回连接getresponse()。状态<400

您可以使用curl。
--head
选项将发送head请求而不是GET,因此即使存在正文,也不会返回正文


curl--head

head
请求是正确的方法,它避免了下载整个文件。