Closed sirEgghead closed 1 year ago
This is a single test request that I made just now. There is no other activity from my app today, besides a few tests from myself. The application worked fine until it decided to start returning status code 429, without any code changes.
Today, after seeing your note about the batch update, I did quickly update the code to send batches, because each translation request that my app creates actually requests for multiple languages. So I am now using the batch request, which should take my 20 requests per day down to maybe 4 per day.
Issue 12 wasn't finished being addressed before it was closed. My app wouldn't hit the rate limit as it sends fewer than 20 requests per day.
I closed it because there was no response after several days of it attempting to be addressed.
This is a single test request that I made just now. There is no other activity from my app today, besides a few tests from myself. The application worked fine until it decided to start returning status code 429, without any code changes.
Can you share your code? I'm not able to reproduce the issue.
const key = require('./api.json')
const { Telegraf } = require('telegraf')
// const fs = require('fs')
const bot = new Telegraf(key.key)
const { Worker } = require('worker_threads')
const translate = require('google-translate-api-x')
bot.start((ctx) => ctx.reply('SSQ Translation Bot'))
bot.on('message', (ctx) => printTranslations(ctx.message.text, ctx))
bot.launch()
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))
async function printTranslations(text, ctx) {
let res = await translateFive(text)
if (res) {
const languages = {
'en': 'English',
'es': 'Español',
'de': 'Deutsch',
'pl': 'Polski',
'ru': 'Русский',
'cn': '中文',
}
let translated = ''
Object.keys(languages).forEach(key => {
translated += `*${languages[key]}:* ${res[key]}`
translated += '\n\n'
})
// ctx.reply(translated, {reply_to_message_id: ctx.message.message_id})
ctx.replyWithMarkdownV2(translated, {reply_to_message_id: ctx.message.message_id})
}
}
async function translateFive(text) {
const textArray = [
{text: text, to: 'en'},
{text: text, to: 'es'},
{text: text, to: 'de'},
{text: text, to: 'ru'},
{text: text, to: 'pl'},
{text: text, to: 'zn-CN'},
];
try {
const translated = await translate(textArray);
return {
'en': translated[0].text,
'es': translated[1].text,
'de': translated[2].text,
'ru': translated[3].text,
'pl': translated[4].text,
'cn': translated[5].text,
}
} catch (e) {
console.log(e.message);
return null;
}
}
console.log('Bot running.')
And this was the original one, as of this morning, before switching to the new batch feature.
const key = require('./api.json')
const { Telegraf } = require('telegraf')
const bot = new Telegraf(key.key)
const { Worker } = require('worker_threads')
const translate = require('google-translate-api-x')
bot.start((ctx) => ctx.reply('SSQ Translation Bot'))
bot.on('message', (ctx) => printTranslations(ctx.message.text, ctx))
bot.launch()
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))
async function printTranslations(text, ctx) {
let res = await translateFive(text)
const languages = {
'en': 'English',
'es': 'Español',
'de': 'Deutsch',
'pl': 'Polski',
'ru': 'Русский',
'cn': '中文',
}
let translated = ''
Object.keys(languages).forEach(key => {
translated += `*${languages[key]}:* ${res[key]}`
translated += '\n\n'
})
ctx.replyWithMarkdownV2(translated, {reply_to_message_id: ctx.message.message_id})
}
async function translateFive(text) {
let en = await translate(text, {to: 'en'})
let es = await translate(text, {to: 'es'})
let de = await translate(text, {to: 'de'})
let ru = await translate(text, {to: 'ru'})
let pl = await translate(text, {to: 'pl'})
let cn = await translate(text, {to: 'zh-CN'})
return {
'en': en.text,
'es': es.text,
'de': de.text,
'ru': ru.text,
'pl': pl.text,
'cn': cn.text,
}
}
console.log('Bot running.')
I migrated the server to a new IP address and I seem to have full operation at this point. Maybe the rate limit being hit was tied to that IP address somehow. Possibly from where I was sending 5 requests per translation. I'm kind of grasping at straws here, but at least for the time being, it seems to be working with the new IP address and using batch requests. I'll update you if anything changes.
I'm kind of grasping at straws here, but at least for the time being, it seems to be working with the new IP address and using batch requests. I'll update you if anything changes.
Okay that's good, my best guess is that Google detected in some way your behavior as malicious and rate limited you, but I can't reproduce it.
Closed as stale
Issue 12 wasn't finished being addressed before it was closed. My app wouldn't hit the rate limit as it sends fewer than 20 requests per day.
Error code 429 is a "too many requests" error. I would assume that your API has a Google Translate API key tied to it? My immediate thought is there are too many users on this "free api" causing the interface to hit the rate limit.