After making the proposed change from #22, the lib works again, however every translation I attempt returns a 429 too many requests, with a message saying PyDeepLX Error: Too many requests, your IP has been blocked by DeepL temporarily, please don't request it frequently in a short time. However this does not appear to be temporary, I have tried it with a vpn, without a vpn, and at all hours of the day, even with days in between. I have no idea if they just started denying the IOS headers OwO-Network was using, but I went ahead and made the following changes to mimic the browser calls. In the PyDeepLX.py file you want to make the following changes...
update the headers dictionary to
headers = {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.9",
"Origin": "https://www.deepl.com",
"Referer": "https://www.deepl.com/",
"X-Requested-With": "XMLHttpRequest",
}
in the translate function of that file, update the postData to...
postData = {
"jsonrpc": "2.0",
"method": "LMT_handle_jobs",
"id": id,
"params": {
"jobs": [
{
"kind": "default",
"raw_en_sentence": text,
"raw_en_context_before": [],
"raw_en_context_after": [],
"preferred_num_beams": numberAlternative + 1,
}
],
"lang": {
"source_lang_user_selected": sourceLang,
"target_lang": targetLang,
},
"priority": 1,
"commonJobParams": {},
"timestamp": getTimestamp(iCount),
},
}
remove or comment out the replace formula to update the method.
# if (id + 5) % 29 == 0 or (id + 3) % 13 == 0:
# postDataStr = postDataStr.replace('"method":"', '"method" : "', -1)
# else:
# postDataStr = postDataStr.replace('"method":"', '"method": "', -1)
Finally, update the dictionary locations of the translated text for return...
if numberAlternative <= 1:
targetText = respJson["result"]["translations"][0]["beams"][0]["postprocessed_sentence"]
if printResult:
print(targetText)
return targetText
targetTextArray = []
for item in respJson["result"]["translations"][0]["beams"]:
targetTextArray.append(item["postprocessed_sentence"])
if printResult:
print(item["text"])
return targetTextArray
Optionally
If you like, you can update the TooManyRequestsException class as below to update the grammar.
class TooManyRequestsException(Exception):
"Raised when there is a 429 error"
def __str__(self):
return "PyDeepLX Error: Too many requests... Your IP has temporarily been blocked by DeepL, please try again later."
and turn the default httpx logging off with
import logging
logging.basicConfig(level=logging.INFO)
httpx_logger = logging.getLogger("httpx")
httpx_logger.setLevel(logging.WARNING)
This should get us back up and running until they block it again.
After making the proposed change from #22, the lib works again, however every translation I attempt returns a 429 too many requests, with a message saying PyDeepLX Error: Too many requests, your IP has been blocked by DeepL temporarily, please don't request it frequently in a short time. However this does not appear to be temporary, I have tried it with a vpn, without a vpn, and at all hours of the day, even with days in between. I have no idea if they just started denying the IOS headers OwO-Network was using, but I went ahead and made the following changes to mimic the browser calls. In the PyDeepLX.py file you want to make the following changes...
update the headers dictionary to
in the translate function of that file, update the postData to...
remove or comment out the replace formula to update the method.
Finally, update the dictionary locations of the translated text for return...
Optionally
If you like, you can update the TooManyRequestsException class as below to update the grammar.
and turn the default httpx logging off with
This should get us back up and running until they block it again.