deepl-translate icon indicating copy to clipboard operation
deepl-translate copied to clipboard

HTTPError: 429 Client Error: Too many requests

Open ptrstn opened this issue 2 years ago • 7 comments

In particular, when running the unit tests, deepl.com sometimes returns an Error 429: Too many requests.

Structured testing should be done to determine when this error occurs and what time periods are allowed without returning an error.

Another approach to fix this is to add a retry_after argument to wait a certain number of milliseconds between each request.

ptrstn avatar Mar 13 '22 10:03 ptrstn

Another solution could be to implement support for proxies as suggested in: https://github.com/ytdl-org/youtube-dl/issues/22839

ptrstn avatar Mar 13 '22 10:03 ptrstn

A potential problem could be that the generated data always contains the exact same id and not the generated one.

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/generators.py#L5-L14

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/generators.py#L41-L64

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/hacks.py#L21-L22

This id should probably be maintained and incremented in a translation session.

ptrstn avatar Mar 13 '22 23:03 ptrstn

A potential problem could be that the generated data always contains the exact same id and not the generated one.

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/generators.py#L5-L14

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/generators.py#L41-L64

https://github.com/ptrstn/deepl-translate/blob/ca61c63ff23031291fbaf220de92018fb85a57f0/deepl/hacks.py#L21-L22

This id should probably be maintained and incremented in a translation session.

Hi, I did some research and believe it is a generated field. Could try decompile the Windows client to get some inspiration

KevinZonda avatar Apr 05 '22 01:04 KevinZonda

Hi, I did some research and believe it is a generated field. Could try decompile the Windows client to get some inspiration

Yes, it is generated and the javascript is quite simply.

utils.chunk.js:1511

var l = 1e4 * Math.round(1e4 * Math.random())

utils.chunk.js:1532

return function h(y, m) {
    var g = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 0
        , b = ++l
        , w = {
        jsonrpc: "2.0",
        method: t,
        params: void 0 !== y ? y : {},
        id: b
    }

In Python:

def generate_id() -> int:
    """
    From utils.chunk.$16023f.js:formatted:1511
    var l = 1e4 * Math.round(1e4 * Math.random())

    :return:
    """
    return int(1e4) * round(1e4 * random.random())

I still experienced the HTTP 429 error though. Not sure when I will find some time to do some experiments.

ptrstn avatar Apr 05 '22 02:04 ptrstn

also deepl uses fake timestamp

Try below

fn gen_fake_timestamp(texts: &Vec<String>) -> u128 {
    let ts = tool::get_epoch_ms();
    let i_count = texts
            .iter()
            .fold(
                1, 
                |s, t| s + t.text.matches('i').count()
            ) as u128;
    ts - ts % i_count + i_count
}

if u know chinese, try read https://zu1k.com/posts/thinking/deception-tactics-in-deepl-api-design/

KevinZonda avatar Apr 05 '22 03:04 KevinZonda

also deepl uses fake timestamp

Try below

fn gen_fake_timestamp(texts: &Vec<String>) -> u128 {
    let ts = tool::get_epoch_ms();
    let i_count = texts
            .iter()
            .fold(
                1, 
                |s, t| s + t.text.matches('i').count()
            ) as u128;
    ts - ts % i_count + i_count
}

if u know chinese, try read https://zu1k.com/posts/thinking/deception-tactics-in-deepl-api-design/

Yes, thanks. Its already implemented in https://github.com/ptrstn/deepl-translate/blob/master/deepl/hacks.py

ptrstn avatar Apr 05 '22 03:04 ptrstn

@ptrstn

image

See https://github.com/rx-ts/deepl-translate/blob/master/src/api.ts#L30-L40

Stringified "method":" need to be changed a bit. 😂

JounQin avatar May 30 '22 13:05 JounQin