import chardet
import urllib.request, urllib.parse, urllib.error
detect = lambda url: chardet.detect(urllib.request.urlopen(url).read())
Is there a Python library function which attempts to guess the character-encoding of some bytes?