🐞Fix: flask_app 中 User-Agent 的问题.

This commit is contained in:
Weclont
2022-07-05 00:49:42 +08:00
parent 17523cbebc
commit 681d363733
6 changed files with 12 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
from smsboom import load_getapi, load_json
from utils.log import logger
from utils.models import API
from utils import default_header
from utils import default_header_user_agent
import httpx
from httpx import Limits
from typing import Union, List
@@ -37,7 +37,7 @@ async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore):
async with httpx.AsyncClient(
limits=Limits(max_connections=1000,
max_keepalive_connections=2000),
headers=default_header,
headers=default_header_user_agent(),
verify=False,
timeout=99999
) as c:

View File

@@ -1,6 +1,6 @@
# encoding=utf8
import httpx
from .model import API, default_header
from .model import API, default_header_user_agent
def test_resq(api: API, phone) -> httpx.Response:
@@ -10,7 +10,7 @@ def test_resq(api: API, phone) -> httpx.Response:
:return: httpx 请求对象.
"""
api = api.handle_API(phone)
with httpx.Client(headers=default_header, timeout=8) as client:
with httpx.Client(headers=default_header_user_agent(), timeout=8) as client:
# 这个判断没意义.....但是我不知道怎么优化...
# https://stackoverflow.com/questions/26685248/difference-between-data-and-json-parameters-in-python-requests-package
# Todo: json 和 data 表单发送的问题,有些服务器不能解释 json,只能接受表单

View File

@@ -10,7 +10,7 @@ from httpx import Limits
import asyncio
from utils.sql import Sql
from utils.req import reqFunc, default_header
from utils.req import reqFunc, default_header_user_agent
from utils.log import logger
path = Path(__file__).parent.absolute().joinpath("debug", "api.db")
@@ -51,7 +51,7 @@ async def test2():
while not q.empty():
i = q.get()
_i = i.replace("[phone]", "19820294267")
async with httpx.AsyncClient(headers=default_header, timeout=100, limits=Limits(max_connections=1000, max_keepalive_connections=20), verify=False) as client:
async with httpx.AsyncClient(headers=default_header_user_agent(), timeout=100, limits=Limits(max_connections=1000, max_keepalive_connections=20), verify=False) as client:
try:
await client.get(_i)
# if r.status_code == 200:

View File

@@ -11,7 +11,7 @@ from concurrent.futures import ThreadPoolExecutor
import time
import sys
import os
from utils import API, default_header
from utils import API, default_header_user_agent
# logger config
logger.remove()
@@ -89,7 +89,7 @@ def req(api: Union[API, str], phone: tuple):
phone_lst = [_ for _ in phone]
else:
phone_lst = [phone]
with httpx.Client(headers=default_header, verify=False) as client:
with httpx.Client(headers=default_header_user_agent(), verify=False) as client:
for ph in phone_lst:
try:
if isinstance(api, API):
@@ -98,7 +98,7 @@ def req(api: Union[API, str], phone: tuple):
logger.info(f"{api.desc}-{resp.text[:30]}")
else:
api = api.replace("[phone]", ph)
resp = client.get(url=api, headers=default_header)
resp = client.get(url=api, headers=default_header_user_agent())
logger.info(f"GETAPI接口-{resp.text[:30]}")
except httpx.HTTPError as why:
logger.error(f"{why.request.url}请求失败{why}")
@@ -149,8 +149,8 @@ def update(proxy: str):
try:
with httpx.Client(verify=False, timeout=10) as client:
# print(API_json_url)
GETAPI_json = client.get(GETAPI_json_url, headers=default_header).content.decode(encoding="utf8")
api_json = client.get(API_json_url, headers=default_header).content.decode(encoding="utf8")
GETAPI_json = client.get(GETAPI_json_url, headers=default_header_user_agent()).content.decode(encoding="utf8")
api_json = client.get(API_json_url, headers=default_header_user_agent()).content.decode(encoding="utf8")
except Exception as why:
logger.error(f"拉取更新失败:{why}请多尝试几次!")

View File

@@ -1 +0,0 @@
127.0.0.1:7890

View File

@@ -89,7 +89,7 @@ async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore):
async with httpx.AsyncClient(
limits=Limits(max_connections=1000,
max_keepalive_connections=2000),
headers=default_header,
headers=default_header_user_agent(),
verify=False,
timeout=99999
) as c: