更新
This commit is contained in:
@@ -7,9 +7,8 @@ import logging
|
||||
import time
|
||||
from typing import Any, Optional
|
||||
|
||||
import requests
|
||||
|
||||
from rpa_engine.device_profiles import resolve_user_agent
|
||||
from rpa_engine.egress_channels import resolve_fixed_channel, source_bound_requests_session
|
||||
from .auth import DouyinAuth
|
||||
from .conv_util import resolve_peer_uid
|
||||
from .dy_util import (
|
||||
@@ -99,6 +98,7 @@ def fetch_peer_profile_sync(
|
||||
session: DouyinImSession,
|
||||
peer_uid: int | str,
|
||||
account_id: int = 0,
|
||||
source_ip: str = "",
|
||||
) -> dict[str, str]:
|
||||
uid = str(peer_uid or "").strip()
|
||||
if not uid.isdigit():
|
||||
@@ -156,21 +156,22 @@ def fetch_peer_profile_sync(
|
||||
"https://www.douyin.com/aweme/v1/web/im/user/info/",
|
||||
]
|
||||
|
||||
proxies = _requests_proxies()
|
||||
proxies = None if source_ip else _requests_proxies()
|
||||
for url in endpoints:
|
||||
try:
|
||||
params = dict(base_params)
|
||||
query = splice_url(params)
|
||||
params["a_bogus"] = generate_a_bogus(query, user_agent=ua)
|
||||
resp = requests.get(
|
||||
url,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=auth.cookie,
|
||||
verify=False,
|
||||
timeout=12,
|
||||
proxies=proxies,
|
||||
)
|
||||
with source_bound_requests_session(source_ip) as client:
|
||||
resp = client.get(
|
||||
url,
|
||||
params=params,
|
||||
headers=headers,
|
||||
cookies=auth.cookie,
|
||||
verify=False,
|
||||
timeout=12,
|
||||
proxies=proxies,
|
||||
)
|
||||
data = resp.json()
|
||||
extracted = _extract_profile_from_payload(data)
|
||||
if extracted.get("uid") and not result["uid"]:
|
||||
@@ -199,12 +200,21 @@ async def fetch_peer_profile(
|
||||
from .traffic_control import get_traffic_controller
|
||||
|
||||
controller = get_traffic_controller()
|
||||
source_ip = str(getattr(session, "egress_source_ip", "") or "").strip()
|
||||
selected_public_ip = str(getattr(session, "egress_public_ip", "") or "").strip()
|
||||
if selected_public_ip and not source_ip:
|
||||
try:
|
||||
route = await resolve_fixed_channel(selected_public_ip)
|
||||
source_ip = str(route.source_ip or "")
|
||||
except Exception as exc:
|
||||
logger.debug("peer profile egress resolution failed: %s", exc)
|
||||
async with controller.background_slot(account_id, "peer profile"):
|
||||
return await asyncio.to_thread(
|
||||
fetch_peer_profile_sync,
|
||||
session,
|
||||
peer_uid,
|
||||
account_id,
|
||||
source_ip,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user