Use requests.Session for embedded images.

This commit is contained in:
Ethan Dalool 2020-11-10 20:23:34 -08:00
parent 94b0274925
commit 8dc7cfa21b

View file

@ -41,6 +41,8 @@ HTML_TEMPLATE = '''
SLUG_CHARACTERS = string.ascii_lowercase + string.digits + '_' SLUG_CHARACTERS = string.ascii_lowercase + string.digits + '_'
session = requests.Session()
class SyntaxHighlighting: class SyntaxHighlighting:
def block_code(self, text, lang): def block_code(self, text, lang):
@ -376,7 +378,7 @@ def embed_images(soup, cache=None):
if cache.get(src) is None: if cache.get(src) is None:
print('Fetching %s' % src) print('Fetching %s' % src)
if src.startswith('https://') or src.startswith('http://'): if src.startswith('https://') or src.startswith('http://'):
response = requests.get(src) response = session.get(src)
response.raise_for_status() response.raise_for_status()
data = response.content data = response.content
else: else: