mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 07:08:03 -05:00
improved user agent for url image import
This commit is contained in:
@@ -961,7 +961,7 @@ class RecipeViewSet(viewsets.ModelViewSet):
|
|||||||
try:
|
try:
|
||||||
url = serializer.validated_data['image_url']
|
url = serializer.validated_data['image_url']
|
||||||
if validators.url(url, public=True):
|
if validators.url(url, public=True):
|
||||||
response = requests.get(url)
|
response = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"})
|
||||||
image = File(io.BytesIO(response.content))
|
image = File(io.BytesIO(response.content))
|
||||||
filetype = mimetypes.guess_extension(response.headers['content-type']) or filetype
|
filetype = mimetypes.guess_extension(response.headers['content-type']) or filetype
|
||||||
except UnidentifiedImageError as e:
|
except UnidentifiedImageError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user