From 78296d996cd3f9a1d4ead07515ab5e248d85b9ab Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 13 Jun 2022 00:43:23 +0800 Subject: [PATCH] Update mw.py --- class/core/mw.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 672bc5697..745d1c5d1 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -546,17 +546,18 @@ def getLocalIp(): import re filename = 'data/iplist.txt' ipaddress = readFile(filename) - if not ipaddress: - import urllib2 + if not ipaddress or ipaddress == '127.0.0.1': + import urllib url = 'http://pv.sohu.com/cityjson?ie=utf-8' - opener = urllib2.urlopen(url) - content = opener.read() + req = urllib.request.urlopen(url, timeout=10) + content = req.read().decode('utf-8') ipaddress = re.search('\d+.\d+.\d+.\d+', content).group(0) writeFile(filename, ipaddress) ipaddress = re.search('\d+.\d+.\d+.\d+', ipaddress).group(0) return ipaddress - except: + except Exception as ex: + # print(ex) return '127.0.0.1'