import urllib.request
import json
import codecs
import time, datetime
import ssl
import tools.tools


# ssl._create_default_https_context = ssl._create_unverified_context
def get_html(url, encode_type="utf-8"):
    while True:
        try:
            # proxy_handler = urllib.request.ProxyHandler({'http': 'http://user:pwd@172.18.32.221:8080'})
            # opener = urllib.request.build_opener(proxy_handler)
            # urllib.request.install_opener(opener)

            resp = urllib.request.urlopen(url, timeout=8)

            reader = codecs.getreader(encode_type)
            return reader(resp).read()
            # return resp.read().decode()
        except Exception as errors:
            print("error", errors)
            return ""
