🐞 fix: 网页的bug

This commit is contained in:
AdminWhaleFall
2022-04-05 18:08:50 +08:00
parent e0c1c18cef
commit 7271caac59
3 changed files with 15 additions and 15 deletions

View File

@@ -56,6 +56,7 @@ def index():
return render_template('admin.html')
@app.route("/testapi/", methods=['POST'])
@logger.catch
def testapi():
brs = BaseResponse()
# 需要传入 json 数据

View File

@@ -44,15 +44,14 @@ class API(BaseModel):
def replace_data(self, content: Union[str, dict], phone) -> str:
if not phone:
return content
if isinstance(content, dict):
for key, value in content.items():
content[key] = value.replace("[phone]", phone).replace(
"[timestamp]", self.timestamp_new())
else:
if isinstance(content, str):
content.replace('[phone]', phone).replace(
'[timestamp]', self.timestamp_new())
return content
# 统一转换成 str 再替换.
content = str(content).replace("[phone]", phone).replace(
"[timestamp]", self.timestamp_new())
# 尝试 json 化
try:
return json.loads(content)
except:
return content
def timestamp_new(self) -> str:
"""返回整数字符串时间戳"""
@@ -63,12 +62,11 @@ class API(BaseModel):
:param API: one API basemodel
:return: API basemodel
"""
if self.method != "POST":
self.method = "GET"
if isinstance(self.data, str):
self.data = json.loads(self.data)
if isinstance(self.header, str):
self.header = json.loads(self.header)
if self.header:
self.header = json.loads(self.header)
self.data = self.replace_data(self.data, phone)
self.url = self.replace_data(self.url, phone)
return self
@@ -81,7 +79,6 @@ def test_resq(api: API, phone) -> httpx.Response:
:return: httpx 请求对象.
"""
api = api.handle_API(phone)
print(api.dict())
with httpx.Client(headers=default_header, timeout=8) as client:
if not isinstance(api.data, dict):
client.request(method=api.method, headers=api.header,
@@ -89,3 +86,7 @@ def test_resq(api: API, phone) -> httpx.Response:
resp = client.request(
method=api.method, headers=api.header, url=api.url, json=api.data)
return resp
if __name__ == '__main__':
pass

View File

@@ -91,8 +91,6 @@ def handle_API(API: API) -> API:
:param API: one API basemodel
:return: API basemodel
"""
if API.method != "POST":
API.method = "GET"
API.data = replace_data(API.data)
API.url = replace_data(API.url)
return API