summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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