Ver Fonte

차차 urllib는 requests로 교체 예정

Surplus_Up (2DU) há 6 anos atrás
pai
commit
5b4c68ce56
5 ficheiros alterados com 18 adições e 4 exclusões
  1. 1 0
      requirements.txt
  2. 5 1
      route/api_skin_info.py
  3. 5 1
      route/api_version.py
  4. 1 1
      route/tool/func.py
  5. 6 1
      route/tool/mark.py

+ 1 - 0
requirements.txt

@@ -3,6 +3,7 @@ bcrypt
 flask
 flask-Reggie
 flask-compress
+requests
 pymysql
 diff-match-patch
 pysha3; python_version < "3.6"

+ 5 - 1
route/api_skin_info.py

@@ -48,7 +48,11 @@ def api_skin_info_2(conn, name):
                     get_num = 0
 
                 if get_num == 1:
-                    get_data = urllib.request.urlopen(info_link)
+                    try:
+                        get_data = urllib.request.urlopen(info_link)
+                    except:
+                        get_data = None
+
                     if get_data and get_data.getcode() == 200:
                         try:
                             get_data = json.loads(get_data.read().decode())

+ 5 - 1
route/api_version.py

@@ -13,7 +13,11 @@ def api_version_2(conn, r_ver, c_ver):
     else:
         up_data = 'stable'
 
-    data = urllib.request.urlopen('https://raw.githubusercontent.com/2du/openNAMU/master/version.json')
+    try:
+        data = urllib.request.urlopen('https://raw.githubusercontent.com/2du/openNAMU/master/version.json')
+    except:
+        data = None
+
     if data and data.getcode() == 200:
         try:
             json_data = json.loads(data.read().decode())

+ 1 - 1
route/tool/func.py

@@ -307,7 +307,7 @@ def captcha_post(re_data, num = 1):
             try:
                 data = urllib.request.urlopen('https://www.google.com/recaptcha/api/siteverify?secret=' + sec_re[0][0] + '&response=' + re_data)
             except:
-                pass
+                data = None
 
             if data and data.getcode() == 200:
                 json_data = json.loads(data.read().decode(data.headers.get_content_charset()))

+ 6 - 1
route/tool/mark.py

@@ -30,7 +30,12 @@ def send_parser(data):
             if re_data:
                 re_data = re_data.groups()[0]
 
-                data = re.sub('&lt;a(?: (?:(?:(?!&gt;).)*))?&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="/w/' + urllib.parse.quote(re_data).replace('/','%2F') + '">' + re_data + '</a>', data, 1)
+                data = re.sub(
+                    '&lt;a(?: (?:(?:(?!&gt;).)*))?&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', 
+                    '<a href="/w/' + urllib.parse.quote(re_data).replace('/','%2F') + '">' + re_data + '</a>', 
+                    data, 
+                    1
+                )
             else:
                 break