Use custom User-Agent and send Accept* headers for better compatibility
This commit is contained in:
parent
6510cdf4df
commit
c2696592b1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue