From ab0f8f9f5e0f2586c0708b753c53ae585069c76f Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sat, 4 Mar 2023 20:53:19 -0600 Subject: fake user agent when fetching images too --- unbiased/util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/unbiased/util.py b/unbiased/util.py index f3c70c0..c5acb89 100644 --- a/unbiased/util.py +++ b/unbiased/util.py @@ -79,12 +79,16 @@ def write_static_files(outDir): def pullImage(url, index, webroot, target_width=350, target_height=200): - res = requests.get(url, timeout=3) + # fake a regular browser user agent for sites that sniff + headers = { + 'User-Agent': u'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36' + } + res = requests.get(url, timeout=3, headers=headers) if res.status_code == 200: content = res.content else: logger.debug('Image not found: url={}'.format(url)) - return '' + raise Exception('image not found') img = Image.open(io.BytesIO(content)) # crop to aspect ratio target_ar = target_width / target_height -- cgit v1.2.3