Skip to content

Commit

Permalink
🐞Fix: flask_app 中 User-Agent 的问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
Weclont committed Jul 4, 2022
1 parent 17523cb commit 681d363
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions celery_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions flask_app/utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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,只能接受表单
Expand Down
4 changes: 2 additions & 2 deletions handle_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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")
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions smsboom_pyinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import time
import sys
import os
from utils import API, default_header
from utils import API, default_header_user_agent

# logger config
logger.remove()
Expand Down Expand Up @@ -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):
Expand All @@ -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}")
Expand Down Expand Up @@ -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}请多尝试几次!")
Expand Down
1 change: 0 additions & 1 deletion socks4_proxy.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
127.0.0.1:7890
2 changes: 1 addition & 1 deletion utils/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 681d363

Please sign in to comment.