gallery.accords-library.com/server/szurubooru/func/net.py

17 lines
523 B
Python
Raw Normal View History

2016-05-05 11:23:15 +00:00
import urllib.request
from szurubooru import config
2016-09-25 12:52:47 +00:00
from szurubooru import errors
2016-05-05 11:23:15 +00:00
def download(url: str) -> bytes:
2016-08-14 08:45:00 +00:00
assert url
2016-05-05 11:23:15 +00:00
request = urllib.request.Request(url)
if config.config['user_agent']:
request.add_header('User-Agent', config.config['user_agent'])
2016-05-05 11:23:15 +00:00
request.add_header('Referer', url)
2016-09-25 12:52:47 +00:00
try:
with urllib.request.urlopen(request) as handle:
return handle.read()
2016-09-26 20:51:00 +00:00
except Exception as ex:
raise errors.ProcessingError('Error downloading %s (%s)' % (url, ex))