Skip to content

Commit

Permalink
🐞 fix: 由单引号引起的 json bug
Browse files Browse the repository at this point in the history
  • Loading branch information
WhaleFell committed Apr 5, 2022
1 parent 9db49b6 commit 16ec481
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 15 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,20 @@
"validate": ""
}
}
},
{
"desc": "果壳app",
"url": "https://guokrapp-apis.guokr.com/hawking/v1/verifications",
"method": "POST",
"header": {
"User-Agent": "android 2.0.15",
"Client-Source": "android;23;Android;MuMu",
"Client-Channel": "gkchannel_QD009",
"Content-Type": "application/json; charset=UTF-8"
},
"data": {
"dial_code": "0086",
"phone": "[phone]"
}
}
]
11 changes: 7 additions & 4 deletions flask_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def replace_data(self, content: Union[str, dict], phone) -> str:
return content
# 统一转换成 str 再替换.
content = str(content).replace("[phone]", phone).replace(
"[timestamp]", self.timestamp_new())
"[timestamp]", self.timestamp_new()).replace("'",'"')
# 尝试 json 化
try:
return json.loads(content)
Expand Down Expand Up @@ -82,10 +82,13 @@ def test_resq(api: API, phone) -> httpx.Response:
api = api.handle_API(phone)
with httpx.Client(headers=default_header, timeout=8) as client:
if not isinstance(api.data, dict):
client.request(method=api.method, headers=api.header,
# print("data")
resp = client.request(method=api.method, headers=api.header,
url=api.url, data=api.data)
resp = client.request(
method=api.method, headers=api.header, url=api.url, json=api.data)
else:
# print('json')
resp = client.request(
method=api.method, headers=api.header, url=api.url, json=api.data)
return resp


Expand Down

0 comments on commit 16ec481

Please sign in to comment.