diff --git a/class/core/public.py b/class/core/public.py index 78dba80c5..140d1909b 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -313,39 +313,90 @@ def writeFile(filename, str): return False -def httpGet(url, timeout=30): - # 发送GET请求 - try: - import urllib2 - import ssl +def HttpGet(url, timeout=10): + """ + 发送GET请求 + @url 被请求的URL地址(必需) + @timeout 超时时间默认60秒 + return string + """ + if sys.version_info[0] == 2: try: - ssl._create_default_https_context = ssl._create_unverified_context - except: - pass - response = urllib2.urlopen(url, timeout=timeout) - return response.read() - except Exception, ex: - # writeLog('网络诊断', str(ex) + '[' + url + ']') - return str(ex) - - -def httpPost(url, data, timeout=30): - # 发送POST请求 - try: - import urllib - import urllib2 - import ssl + import urllib2 + import ssl + if sys.version_info[0] == 2: + reload(urllib2) + reload(ssl) + try: + ssl._create_default_https_context = ssl._create_unverified_context + except: + pass + response = urllib2.urlopen(url, timeout=timeout) + return response.read() + except Exception as ex: + return str(ex) + else: + try: + import urllib.request + import ssl + try: + ssl._create_default_https_context = ssl._create_unverified_context + except: + pass + response = urllib.request.urlopen(url, timeout=timeout) + result = response.read() + if type(result) == bytes: + result = result.decode('utf-8') + return result + except Exception as ex: + return str(ex) + + +def httpGet(url, timeout=10): + return HttpGet(url, timeout) + + +def HttpPost(url, data, timeout=10): + """ + 发送POST请求 + @url 被请求的URL地址(必需) + @data POST参数,可以是字符串或字典(必需) + @timeout 超时时间默认60秒 + return string + """ + if sys.version_info[0] == 2: try: + import urllib + import urllib2 + import ssl ssl._create_default_https_context = ssl._create_unverified_context - except: - pass - data = urllib.urlencode(data) - req = urllib2.Request(url, data) - response = urllib2.urlopen(req, timeout=timeout) - return response.read() - except Exception, ex: - # WriteLog('网络诊断',str(ex) + '['+url+']'); - return str(ex) + data = urllib.urlencode(data) + req = urllib2.Request(url, data) + response = urllib2.urlopen(req, timeout=timeout) + return response.read() + except Exception as ex: + return str(ex) + else: + try: + import urllib.request + import ssl + try: + ssl._create_default_https_context = ssl._create_unverified_context + except: + pass + data = urllib.parse.urlencode(data).encode('utf-8') + req = urllib.request.Request(url, data) + response = urllib.request.urlopen(req, timeout=timeout) + result = response.read() + if type(result) == bytes: + result = result.decode('utf-8') + return result + except Exception as ex: + return str(ex) + + +def httpPost(url, data, timeout=10): + return HttpPost(url, data, timeout) def writeSpeed(title, used, total, speed=0): diff --git a/plugins/php/versions/phplib.conf b/plugins/php/versions/phplib.conf index 3b5678712..621e4507b 100755 --- a/plugins/php/versions/phplib.conf +++ b/plugins/php/versions/phplib.conf @@ -291,7 +291,6 @@ "53", "54", "55", - "56", "70", "71" ], @@ -401,7 +400,6 @@ "53", "54", "55", - "56", "70", "71" ], @@ -417,7 +415,6 @@ "53", "54", "55", - "56", "70", "71" ], diff --git a/route/__init__.py b/route/__init__.py index 97093b4da..71b93e10b 100755 --- a/route/__init__.py +++ b/route/__init__.py @@ -93,6 +93,7 @@ def publicObject(toObject, func, action=None, get=None): @app.route("/test") def test(): + print sys.version_info print session os = public.getOs() print os