MCPcopy Create free account
hub / github.com/NanmiCoder/MediaCrawler / StaticProxyProvider

Class StaticProxyProvider

proxy/proxy_ip_pool.py:155–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153
154
155class StaticProxyProvider(ProxyProvider):
156 async def get_proxy(self, num: int) -> List[IpInfoModel]:
157 proxy_url = getattr(config, "STATIC_PROXY_URL", "")
158 if not proxy_url:
159 utils.logger.warning("[StaticProxyProvider] STATIC_PROXY_URL is not configured!")
160 return []
161
162 try:
163 parsed = urlparse(proxy_url)
164 scheme = parsed.scheme or "http"
165 if scheme not in {"http", "https"}:
166 utils.logger.error(f"[StaticProxyProvider] Unsupported proxy scheme: {scheme}")
167 return []
168
169 ip = parsed.hostname or ""
170 port = parsed.port or (443 if scheme == "https" else 80)
171 if not ip:
172 utils.logger.error("[StaticProxyProvider] STATIC_PROXY_URL host is empty!")
173 return []
174
175 return [
176 IpInfoModel(
177 ip=ip,
178 port=port,
179 user=unquote(parsed.username or ""),
180 password=unquote(parsed.password or ""),
181 protocol=f"{scheme}://",
182 # Static proxy doesn't expire.
183 expired_time_ts=int(time.time()) + 99999999,
184 )
185 ]
186 except Exception as e:
187 utils.logger.error(f"[StaticProxyProvider] Parse static proxy url error: {e}")
188 return []
189
190
191IpProxyProvider: Dict[str, ProxyProvider] = {

Calls

no outgoing calls