From 9e239d556eec43c8017d488300b7616c4d3e8606 Mon Sep 17 00:00:00 2001 From: Shurelol Date: Tue, 9 May 2023 13:24:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=97=A0=E6=B3=95=E8=BF=9E=E6=8E=A5sp0.b?= =?UTF-8?q?aidu.com=E6=97=B6=E6=97=A0=E6=B3=95=E5=8F=91=E9=80=81=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E6=92=AD=E6=94=BE=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/backend/web_utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/web/backend/web_utils.py b/web/backend/web_utils.py index c61cbfa0..9039ba24 100644 --- a/web/backend/web_utils.py +++ b/web/backend/web_utils.py @@ -23,13 +23,16 @@ def get_location(ip): url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?co=&resource_id=6006&t=1529895387942&ie=utf8' \ '&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&' \ 'cb=jQuery110203920624944751099_1529894588086&_=1529894588088&query=%s' % ip - r = RequestUtils().get_res(url) - r.encoding = 'gbk' - html = r.text try: - c1 = html.split('location":"')[1] - c2 = c1.split('","')[0] - return c2 + r = RequestUtils().get_res(url) + if r: + r.encoding = 'gbk' + html = r.text + c1 = html.split('location":"')[1] + c2 = c1.split('","')[0] + return c2 + else: + return "" except Exception as err: ExceptionUtils.exception_traceback(err) return ""