fix webhooks
This commit is contained in:
@ -5,6 +5,8 @@ import urllib3
|
||||
from requests import Session, Response
|
||||
from urllib3.exceptions import InsecureRequestWarning
|
||||
|
||||
from app.utils.ip import IpUtils
|
||||
|
||||
urllib3.disable_warnings(InsecureRequestWarning)
|
||||
|
||||
|
||||
@ -150,7 +152,7 @@ class RequestUtils:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def cookie_parse(cookies_str: str, array: bool = False) -> dict:
|
||||
def cookie_parse(cookies_str: str, array: bool = False) -> Union[list, dict]:
|
||||
"""
|
||||
解析cookie,转化为字典或者数组
|
||||
:param cookies_str: cookie字符串
|
||||
@ -172,3 +174,29 @@ class RequestUtils:
|
||||
cookiesList.append(cookies)
|
||||
return cookiesList
|
||||
return cookie_dict
|
||||
|
||||
|
||||
class WebUtils:
|
||||
|
||||
@staticmethod
|
||||
def get_location(ip):
|
||||
"""
|
||||
根据IP址查询真实地址
|
||||
"""
|
||||
if not IpUtils.is_ipv4(ip):
|
||||
return ""
|
||||
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
|
||||
try:
|
||||
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:
|
||||
return str(err)
|
||||
|
Reference in New Issue
Block a user