Skip to content

Commit

Permalink
Update utils.py for validate_url (#4388)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
alvindaiyan and abidlabs authored Jun 2, 2023
1 parent 631403d commit 728ed32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 2 additions & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 728ed32

Please sign in to comment.