zorbaTheRainy / autotranslate

A script/docker that automatically translates PDFs using the DeepL API
MIT License
4 stars 0 forks source link

Great work but... #1

Closed JosefAschauer closed 1 month ago

JosefAschauer commented 1 month ago

First of all: THANK you! I was looking for such a great tool Unfortuately for me the container crashes (using compose) and I am hoping you can help me to get this up. API key is installed...

part of the log:

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/translators/server.py", line 259, in get_server_region data = json.loads(requests.get(self.get_addr_url, headers=_headers_fn(self.get_addr_url)).text[9:-2]) File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 73, in get return request("get", url, params=params, kwargs) File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, kwargs) File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, kwargs) File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='geolocation.onetrust.com', port=443): Max retries exceeded with url: /cookieconsentpub/v1/geo/location (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe055d1cfd0>: Failed to establish a new connection: [Errno 111] Connection refused'))

zorbaTheRainy commented 1 month ago

I'll look into it. Although this is vacation season. So, I am sorry but it might take a while

What is your region? What is your docker version? Architecture, etc ?

JosefAschauer commented 1 month ago

Thanks mate. My Region is DE

JosefAschauer commented 1 month ago

Hi,

It was the geolocation link, my pi-hole didn't like it. After disabling ir for 30 seconds, the container started.

Can it handle the free api key since deepl uses 2 different URLs? https://support.deepl.com/hc/en-us/articles/360021183620-DeepL-API-Free-vs-DeepL-API-Pro

I'm now getting this using the free api key, key is corect, I doublechecked: ... Attempting to establish communication with the Web API server. Using normal Web API server.

Unexpected error occurred when trying to determine the API usage allowance. Authorization failure, check auth_key Putting the program to sleep for 15 minute(s).

zorbaTheRainy commented 1 month ago

I am glad you found the problem. I admit I wasn't going to look at this until Wednesday when my guests left.

Unfortunately, the traceback logs don't give me an error in autotranslate.py only the python libraries (e.g., server.py, api.py. etc.).


On to the Free vs Pro issue. Truthfully, I have never tried the Pro API key. I have always wanted to but by the time I wrote this script my need to process many documents per month had passed. My initial answer is, "It should support both Free and Pro. The DeepL API should take care of that."

I'll have more time to look at this after Wednesday. (again sorry for the wait.) My initial thoughts are ...

From the API docs:

Note: The API domain differs depending on whether you are using DeepL API Free or DeepL API Pro:

For DeepL API Free: api-free.deepl.com
For DeepL API Pro: api.deepl.com

Without configuration overrides (env vars), autotranslate.py tries the URL built into the DeepL API module.

Which states:

Server URL configuration
You can override the URL of the DeepL API by specifying the server_url argument when constructing a deepl.Translator. This may be useful for testing purposes.   
You do not need to specify the URL to distinguish API Free and API Pro accounts, the library selects the correct URL automatically.

Since the deepl Python module is on GitHub, I can look at how it does things.

In deepl-python/deepl/translator.py line 94 it states:

        if server_url is None:
            server_url = (
                self._DEEPL_SERVER_URL_FREE
                if util.auth_key_is_free_account(auth_key)
                else self._DEEPL_SERVER_URL
            )

and on line 74

    _DEEPL_SERVER_URL = "https://api.deepl.com"
    _DEEPL_SERVER_URL_FREE = "https://api-free.deepl.com"

So, deepl module should be using the correct URL, if your API key is Free or Pro. Messing around with the autotranslate.py's DEEPL_SERVER_URL env variable should not be necessary. The deepl module should handle everything itself. But, I would test explicitly stating the url api.deepl.com just to make sure that it isn't a problem with your API key (which I suspect it is).

autotranslate.py feeds deepl a default URL (line 601), unless you override it with the DEEPL_SERVER_URL env variable (which gets into autotranslate.py as the python variable "serverURL"):

  logger.info(f"Attempting to establish communication with the Web API server.")
  if serverURL != "":
    logger.info(f"\tUsing custom Web API server: {serverURL}") # keep as INFO as it is such a rare occurrence that the event should be noted in the log
    translator = deepl.Translator(auth_key, server_url=serverURL)
  else:
    logger.debug(f"\tUsing normal Web API server.")
    translator = deepl.Translator(auth_key)

.

.

It should be noted that autotranslate only supports 1 API at a time. If you want to use 2 API keys you need to run 2 instances of autotranlaste. I am assuming you're not doing something like trying to put in 2 API keys at the same time.

JosefAschauer commented 1 month ago

I registered a new free api account since my other key came from a degraded pro account and its now connecting finally :)

JosefAschauer commented 1 month ago

Oh, btw, Microsoft's free translation api gives you 2 million characters per month. Any plans to implement? https://www.microsoft.com/en-us/translator/business/translator-api/ -> scalable https://www.microsoft.com/en-us/translator/business/trial/#get-started

zorbaTheRainy commented 1 month ago

Glad it is working for you. And glad it is useful for you.

I may add more translators, but might not.

Take care. I'll close this now.