Use custom User-Agent and send Accept* headers for better compatibility

This commit is contained in:
Juhani Krekelä 2023-09-10 13:15:18 +03:00
parent 6510cdf4df
commit c2696592b1
1 changed files with 8 additions and 1 deletions

View File

@ -138,7 +138,14 @@ def handle_message(*, prefix, message, nick, channel, irc):
try:
try:
with urllib.request.urlopen(url, timeout = 5) as response:
headers = {
'User-Agent': 'Cockatric4 (like Lynx)',
'Accept': '*/*',
'Accept-Language': 'en,*;q=0.1',
'Accept-Charset': 'utf-8',
}
request = urllib.request.Request(url, headers = headers)
with urllib.request.urlopen(request, timeout = 5) as response:
if response.info().get_content_type() == 'text/html':
# First 4KiB of a page should be enough for any <title>
# Turns out it's not, so download 64KiB