Bläddra i källkod

[update] verify_host use env

chemf 6 år sedan
förälder
incheckning
6ac70ab73f
3 ändrade filer med 8 tillägg och 2 borttagningar
  1. 4 0
      Config/ConfigGetter.py
  2. 2 1
      Config/setting.py
  3. 2 1
      Util/utilFunction.py

+ 4 - 0
Config/ConfigGetter.py

@@ -57,6 +57,10 @@ class ConfigGetter(object):
     def host_port(self):
         return SERVER_API.get("PORT", 5010)
 
+    @LazyProperty
+    def verify_host(self):
+        return VERIFY_HOST
+
 
 config = ConfigGetter()
 

+ 2 - 1
Config/setting.py

@@ -10,7 +10,6 @@
                    2019/2/15:
 -------------------------------------------------
 """
-
 import sys
 from os import getenv
 from logging import getLogger
@@ -73,6 +72,8 @@ SERVER_API = {
     "PORT": 5010  # port number to which the server listens to
 }
 
+VERIFY_HOST = getenv('proxy_verify_host', 'http://www.baidu.com')
+
 
 class ConfigError(BaseException):
     pass

+ 2 - 1
Util/utilFunction.py

@@ -15,6 +15,7 @@ import requests
 from lxml import etree
 
 from Util.WebRequest import WebRequest
+from Config.ConfigGetter import config
 
 
 def robustCrawl(func):
@@ -86,7 +87,7 @@ def validUsefulProxy(proxy):
         proxy = proxy.decode("utf8")
     proxies = {"http": "http://{proxy}".format(proxy=proxy)}
     try:
-        r = requests.get('http://www.baidu.com', proxies=proxies, timeout=10, verify=False)
+        r = requests.get(config.verify_host, proxies=proxies, timeout=10, verify=False)
         if r.status_code == 200:
             return True
     except Exception as e: