DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
202 stars 23 forks source link

413 Request Entity Too Large #40

Closed grandeljay closed 7 months ago

grandeljay commented 8 months ago

I am trying to translate 1009 lines of text (312 KiB) in a single POST request via a WordPress plugin I created and can't due to a generic internal server error (HTTP 500). After inspecting the logs, I found this client error:

PHP Fatal error:  Uncaught DeepL\DeepLException: Unexpected status code: 413 , <html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>
, content: <html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>

I've done some brief research, to find that the maximum possible size of a POST request is limited by the server, as well as the client by doing something like: min(serverMaxSize, clientMaxSize). Since it's a HTTP 4xx error, I presume the fault lies within the library/client here?

Here are some of my server settings (php.ini), which look fine to me: Key Value Description
max_input_vars 1000 PHP max input variables
max_execution_time 30 PHP time limit
memory_limit 512M PHP memory limit
max_input_time 60 Max input time
upload_max_filesize 50M Upload max filesize
post_max_size 50M PHP post max size

Any ideas are greatly appreciated! Thanks for making this open source!

JanEbbing commented 8 months ago

Yes, you are running into a limitation of the API - requests must be below 128K in size (to stay within that limit, we recommend to limit texts to translate to 105-110KB). We don't handle larger texts in the client libraries yet (e.g. by splitting a large request into multiple smaller ones), since we want to ensure maximum translation quality and it's not easily possible to split a text while preserving this quality. Do you see a way to adhere to that limit, even for a larger WP post? (Also please note, we do not provide the WP Plugin but the Client library it uses.)

grandeljay commented 8 months ago

API - requests must be below 128K in size

Alright, good to know!

We don't handle larger texts in the client libraries yet (e.g. by splitting a large request into multiple smaller ones), since we want to ensure maximum translation quality and it's not easily possible to split a text while preserving this quality.

That's no problem for me. I was just trying to find a way to determine what the POST max size is, so I can enforce it. Now I know, thanks!

Do you see a way to adhere to that limit, even for a larger WP post?

My plugin is actually a simple UI for translating structured content (html, xml), since I don't believe DeepL offers a GUI for that anywhere. I'll just simply limit the input to ~110 KiB