Skip to content

Commit

Permalink
Merge pull request #73 from sinedie/retry-proxy-exception
Browse files Browse the repository at this point in the history
Retry on getting proxy exception
  • Loading branch information
sinedie authored Dec 3, 2023
2 parents 56bf1d7 + c18bd8e commit 1f42f7e
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions srtranslator/translators/selenium_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@ def create_proxy(country_id: Optional[List[str]] = ["US"]) -> Proxy:
Returns:
Proxy: Selenium WebDriver proxy
"""
logging.info("Getting a new Proxy from https://www.sslproxies.org/")
proxy = FreeProxy(country_id=country_id).get()
proxy = Proxy(
dict(
proxyType=ProxyType.MANUAL,
httpProxy=proxy,
ftpProxy=proxy,
sslProxy=proxy,
noProxy="",
)
)
return proxy
i = 0
while i < 3:
try:
logging.info("Getting a new Proxy from https://www.sslproxies.org/")
proxy = FreeProxy(country_id=country_id).get()
proxy = Proxy(
dict(
proxyType=ProxyType.MANUAL,
httpProxy=proxy,
ftpProxy=proxy,
sslProxy=proxy,
noProxy="",
)
)
return proxy
except:
logging.info("Exception while getting Proxy. Trying again")
i += 1

raise Exception("Unable to get proxy")


def create_driver(proxy: Optional[Proxy] = None) -> WebDriver:
Expand Down

0 comments on commit 1f42f7e

Please sign in to comment.