diff --git a/googletrans/client.py b/googletrans/client.py index aab1ccf..de107b0 100644 --- a/googletrans/client.py +++ b/googletrans/client.py @@ -15,6 +15,7 @@ from googletrans import urls, utils from googletrans.gtoken import TokenAcquirer from googletrans.constants import ( + DEFAULT_CLIENT_SERVICE_URLS, DEFAULT_USER_AGENT, LANGCODES, LANGUAGES, SPECIAL_CASES, DEFAULT_RAISE_EXCEPTION, DUMMY_DATA ) @@ -51,7 +52,7 @@ class Translator: :type raise_exception: boolean """ - def __init__(self, service_urls=None, user_agent=DEFAULT_USER_AGENT, + def __init__(self, service_urls=DEFAULT_CLIENT_SERVICE_URLS, user_agent=DEFAULT_USER_AGENT, raise_exception=DEFAULT_RAISE_EXCEPTION, proxies: typing.Dict[str, httpcore.SyncHTTPTransport] = None, timeout: Timeout = None, @@ -87,7 +88,7 @@ def __init__(self, service_urls=None, user_agent=DEFAULT_USER_AGENT, self.client_type = 'webapp' self.token_acquirer = TokenAcquirer( client=self.client, host=self.service_urls[0]) - + self.raise_exception = raise_exception def _pick_service_url(self): diff --git a/googletrans/constants.py b/googletrans/constants.py index 3063b19..9d80b6d 100644 --- a/googletrans/constants.py +++ b/googletrans/constants.py @@ -1,5 +1,9 @@ DEFAULT_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' +DEFAULT_CLIENT_SERVICE_URLS = ( + 'translate.googleapis.com', +) + DEFAULT_SERVICE_URLS = ('translate.google.ac', 'translate.google.ad', 'translate.google.ae', 'translate.google.al', 'translate.google.am', 'translate.google.as', 'translate.google.at', 'translate.google.az', 'translate.google.ba', @@ -21,21 +25,21 @@ 'translate.google.com.ai', 'translate.google.com.ar', 'translate.google.com.au', 'translate.google.com.bd', 'translate.google.com.bh', 'translate.google.com.bn', 'translate.google.com.bo', 'translate.google.com.br', 'translate.google.com.bz', - 'translate.google.com.co', 'translate.google.com.cu', 'translate.google.com.cy', - 'translate.google.com.do', 'translate.google.com.ec', 'translate.google.com.eg', - 'translate.google.com.et', 'translate.google.com.fj', 'translate.google.com.gh', - 'translate.google.com.gi', 'translate.google.com.gt', 'translate.google.com.hk', - 'translate.google.com.jm', 'translate.google.com.kh', 'translate.google.com.kw', - 'translate.google.com.lb', 'translate.google.com.ly', 'translate.google.com.mm', - 'translate.google.com.mt', 'translate.google.com.mx', 'translate.google.com.my', - 'translate.google.com.na', 'translate.google.com.ng', 'translate.google.com.ni', - 'translate.google.com.np', 'translate.google.com.om', 'translate.google.com.pa', - 'translate.google.com.pe', 'translate.google.com.pg', 'translate.google.com.ph', - 'translate.google.com.pk', 'translate.google.com.pr', 'translate.google.com.py', - 'translate.google.com.qa', 'translate.google.com.sa', 'translate.google.com.sb', - 'translate.google.com.sg', 'translate.google.com.sl', 'translate.google.com.sv', - 'translate.google.com.tj', 'translate.google.com.tr', 'translate.google.com.tw', - 'translate.google.com.ua', 'translate.google.com.uy', 'translate.google.com.vc', + 'translate.google.com.co', 'translate.google.com.cu', 'translate.google.com.cy', + 'translate.google.com.do', 'translate.google.com.ec', 'translate.google.com.eg', + 'translate.google.com.et', 'translate.google.com.fj', 'translate.google.com.gh', + 'translate.google.com.gi', 'translate.google.com.gt', 'translate.google.com.hk', + 'translate.google.com.jm', 'translate.google.com.kh', 'translate.google.com.kw', + 'translate.google.com.lb', 'translate.google.com.ly', 'translate.google.com.mm', + 'translate.google.com.mt', 'translate.google.com.mx', 'translate.google.com.my', + 'translate.google.com.na', 'translate.google.com.ng', 'translate.google.com.ni', + 'translate.google.com.np', 'translate.google.com.om', 'translate.google.com.pa', + 'translate.google.com.pe', 'translate.google.com.pg', 'translate.google.com.ph', + 'translate.google.com.pk', 'translate.google.com.pr', 'translate.google.com.py', + 'translate.google.com.qa', 'translate.google.com.sa', 'translate.google.com.sb', + 'translate.google.com.sg', 'translate.google.com.sl', 'translate.google.com.sv', + 'translate.google.com.tj', 'translate.google.com.tr', 'translate.google.com.tw', + 'translate.google.com.ua', 'translate.google.com.uy', 'translate.google.com.vc', 'translate.google.com.vn', 'translate.google.com', 'translate.google.cv', 'translate.google.cz', 'translate.google.de', 'translate.google.dj', 'translate.google.dk', 'translate.google.dm', 'translate.google.dz', @@ -65,9 +69,9 @@ 'translate.google.st', 'translate.google.td', 'translate.google.tg', 'translate.google.tk', 'translate.google.tl', 'translate.google.tm', 'translate.google.tn', 'translate.google.to', 'translate.google.tt', - 'translate.google.us', 'translate.google.vg', 'translate.google.vu', + 'translate.google.us', 'translate.google.vg', 'translate.google.vu', 'translate.google.ws') - + SPECIAL_CASES = { 'ee': 'et', }