Update utils.py for validate_url (#4388)

* Update utils.py for validate_url

AWS s3 presigned url cannot work for both HEAD and GET. So when HEAD the presigned url, it will return 403(Forbidden)

* Update gradio/utils.py

* changelog

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Yan 2023-06-02 09:59:21 +08:00 committed by GitHub
parent 631403d8c5
commit 728ed32b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -7,6 +7,7 @@ No changes to highlight.
## Bug Fixes:
- Allow gradio to work offline, by [@aliabid94](https://github.com/aliabid94) in [PR 4398](https://github.com/gradio-app/gradio/pull/4398).
- Fixed `validate_url` to check for 403 errors and use a GET request in place of a HEAD by [@alvindaiyan](https://github.com/alvindaiyan) in [PR 4388](https://github.com/gradio-app/gradio/pull/4388).
## Other Changes:

View File

@ -616,7 +616,8 @@ def validate_url(possible_url: str) -> bool:
headers = {"User-Agent": "gradio (https://gradio.app/; team@gradio.app)"}
try:
head_request = requests.head(possible_url, headers=headers)
if head_request.status_code == 405:
# some URLs, such as AWS S3 presigned URLs, return a 405 or a 403 for HEAD requests
if head_request.status_code == 405 or head_request.status_code == 403:
return requests.get(possible_url, headers=headers).ok
return head_request.ok
except Exception: