Error Code 1010 calling POST translate

I’m using some Javascript to call the Translate API using XMLHttpRequest and I’m getting an error code 1010 returned.
I have a Content-Type header set of ‘aplication/json’; are there other header requirements?

Mm, are you able to make a request by simply visiting https://libretranslate.com ?

Yes, it works fine in the browser

Here is my JS snippet (the input1[0] etc are passed into the process from a controlling app)

addLibrary(“http”);

var params = “?q=” + input1[0] + “&source=” + input1[1] + “&target=” + input1[2] + “&format=” + input1[3] + “&api_key=” + input1[4];
var url = “https://libretranslate.com/translate” + encodeURI(params);
var xmlHttp = new XMLHttpRequest();
xmlHttp.open(“POST”, url, false);
xmlHttp.setRequestHeader(“Content-Type”,“application/json”);
xmlHttp.send();

var output1 = “” + xmlHttp.responseXML;

I would try to pass the parameters as POST body parameters rather than with query parameters (?q= …). Also, is the code running from the same network as your browser (or is it running on a server somewhere else?)

I’ll try the body parameters. Code is on the same network as the browser

I tried the following, sending the parameters as body. Still Error Code 1010 I’m afraid.

addLibrary(“http”);

var json = {
“q”: + input1[0],
“source”: input1[1],
“target”: input1[2],
“format”: input1[3],
“api_key”: input1[4]
};

var xhr = new XMLHttpRequest();
xhr.open(“POST”, “https://libretranslate.com/translate”, false);
xhr.setRequestHeader(“Content-Type”,“application/json”);
xhr.send(JSON.stringify(json));

var output1 = “” + xhr.responseXML;

I think error 1010 could be a Cloudflare error, libretranslate.com uses Cloudflare.

1 Like

Details on resolving 1010 from CloudFlare. This suggests changes at the LibreTranslate end can resolve this. However, as I’m calling programmatically rather than via a browser, it may be that I need to be sending additional headers or somesuch? https://support.cloudflare.com/hc/en-us/articles/360029779472-Troubleshooting-Cloudflare-1XXX-errors#error1010

2 Likes

@argosopentech thanks for the lead. The latest change has certainly moved the needle with a User-agent header seeming to please CloudFlare and get me through to the endpoint

xhr.setRequestHeader(“User-agent”,“17.0.4”);

2 Likes

Thanks for sharing the solution!

That’s really strange of cloudflare; we didn’t set any blocking rules for user-agent. It looks like they might be blocking user-agent-less requests by default?

2 Likes