summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Singleton <matt@xcolour.net>2023-03-04 20:53:19 -0600
committerMatt Singleton <matt@xcolour.net>2023-03-04 20:53:19 -0600
commitab0f8f9f5e0f2586c0708b753c53ae585069c76f (patch)
tree6c5758b8c161ed33d4edd0232bf7bbbc73c2b52c
parenta8b4d286d31d56f16219c064d7697a06f319d813 (diff)
fake user agent when fetching images tooHEADmain
-rw-r--r--unbiased/util.py8
1 files 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