mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
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:
parent
631403d8c5
commit
728ed32b81
@ -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:
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user