import urllib.request def create(url, format="simple", logstats=False): ascii_url = "" for c in url: if c in "1234567890qwertyuiopasdfghjklzxcvbnm.": ascii_url += c else: ascii_url += "%" + str(int(str(ord(c)), 16)) query_params = f"?format={format}&url={url}&logstats={1 if logstats else 0}" # Because unfortunately is.gd doesn't trust `Python-urllib/{your python version}`, though they have an API user_agent = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)", } request = urllib.request.Request("https://is.gd/create.php" + query_params, None, user_agent) with urllib.request.urlopen(request) as response: return response.read().decode("utf-8")