Skip to content

Commit

Permalink
Merge pull request #301 from bsormagec/patch-4
Browse files Browse the repository at this point in the history
add user-agent image request
  • Loading branch information
mrhan1993 authored Apr 18, 2024
2 parents 526d965 + 63d74bd commit 93edabd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fooocusapi/utils/img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ def get_check_image(url: str) -> UploadFile | None:
"""
if url == '':
return None
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}
try:
response = requests.get(url, timeout=10)
response = requests.get(url, headers=headers, timeout=10)
binary_image = response.content
except Exception:
return None
try:
buffer = BytesIO(binary_image)
Image.open(buffer)
Image.open(buffer) # This validates the image
except Exception:
return None
byte_stream = BytesIO()
Expand Down

0 comments on commit 93edabd

Please sign in to comment.