MCPcopy Create free account
hub / github.com/apify/crawlee-python / new_proxy_info

Method new_proxy_info

src/crawlee/proxy_configuration.py:114–157  ·  view source on GitHub ↗

Return a new ProxyInfo object based on the configured proxy rotation strategy. Args: session_id: Session identifier. If provided, same proxy URL will be returned for subsequent calls with this ID. Will be auto-generated for tiered proxies if not p

(
        self, session_id: str | None, request: Request | None, proxy_tier: int | None
    )

Source from the content-addressed store, hash-verified

112 return URL(url)
113
114 async def new_proxy_info(
115 self, session_id: str | None, request: Request | None, proxy_tier: int | None
116 ) -> ProxyInfo | None:
117 """Return a new ProxyInfo object based on the configured proxy rotation strategy.
118
119 Args:
120 session_id: Session identifier. If provided, same proxy URL will be returned for
121 subsequent calls with this ID. Will be auto-generated for tiered proxies if
122 not provided.
123 request: Request object used for proxy rotation and tier selection. Required for
124 tiered proxies to track retries and adjust tier accordingly.
125 proxy_tier: Specific proxy tier to use. If not provided, will be automatically
126 selected based on configuration.
127 """
128 if self._proxy_tier_tracker is not None and session_id is None:
129 session_id = crypto_random_object_id(6)
130
131 url, proxy_tier = await self._pick_url(session_id, request, proxy_tier)
132
133 if url is None:
134 return None
135
136 if url.port is None:
137 raise ValueError(f'Port is None for URL: {url}')
138
139 if url.host is None:
140 raise ValueError(f'Host is None for URL: {url}')
141
142 info = ProxyInfo(
143 url=str(url),
144 scheme=url.scheme,
145 hostname=url.host,
146 port=url.port,
147 username=url.user or '',
148 password=url.password or '',
149 )
150
151 if session_id is not None:
152 info.session_id = session_id
153
154 if proxy_tier is not None:
155 info.proxy_tier = proxy_tier
156
157 return info
158
159 async def new_url(
160 self, session_id: str | None = None, request: Request | None = None, proxy_tier: int | None = None

Calls 3

_pick_urlMethod · 0.95
crypto_random_object_idFunction · 0.90
ProxyInfoClass · 0.85