From cab36c8ac63acd7ceadcfcf8856cf2f3607bf8ed Mon Sep 17 00:00:00 2001 From: rra Date: Sun, 29 May 2022 14:45:11 +0200 Subject: [PATCH] add less generic headers --- lumbunglib/feed.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lumbunglib/feed.py b/lumbunglib/feed.py index a78c032..f5a8d42 100644 --- a/lumbunglib/feed.py +++ b/lumbunglib/feed.py @@ -194,13 +194,17 @@ def grab_media(post_directory, url, prefered_name=None): """ media_item = urlparse(url).path.split('/')[-1] + headers = { + 'User-Agent': 'https://git.autonomic.zone/ruangrupa/lumbunglib', + 'From': 'info@lumbung.space' # This is another valid field + } if prefered_name: media_item = prefered_name try: if not os.path.exists(os.path.join(post_directory, media_item)): #TODO: stream is true is a conditional so we could check the headers for things, mimetype etc - response = requests.get(url, stream=True) + response = requests.get(url, headers=headers, stream=True) if response.ok: with open(os.path.join(post_directory, media_item), 'wb') as media_file: shutil.copyfileobj(response.raw, media_file)