Closed flyeven closed 3 years ago
Hi, 是否是临时的网络问题?我刚刚运行了测试用例,结果显示并无异常。
我也测了下,只运行测试代码正常。可能是并发大量翻译造成的。
使用 google translate api 也有类似问题。单个测试大概能过。大量请求基本都是 RequestError 。看来还要想办法注册key。
另外,刚才测试中出现 translate is not a function
错误。
改为 import { translate as trans_bing } from 'bing-translate-api';
用 trans_bing 就没错了。遇到过这种问题吗?
下面是 google translation 的错误信息。
GotError [RequestError]: socket hang up
at ClientRequest.<anonymous> (D:\Programming\nodescraping\node_modules\got\source\request-as-event-emitter.js:178:14)
at Object.onceWrapper (events.js:422:26)
at ClientRequest.emit (events.js:327:22)
at ClientRequest.origin.emit (D:\Programming\nodescraping\node_modules\@szmarczak\http-timer\source\index.js:37:11)
at TLSSocket.socketOnEnd (_http_client.js:493:9)
at TLSSocket.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'ECONNRESET',
host: 'translate.google.com',
hostname: 'translate.google.com',
method: 'GET',
path: '/',
socketPath: undefined,
protocol: 'https:',
url: 'https://translate.google.com/',
gotOptions: {
path: '/',
protocol: 'https:',
slashes: true,
auth: null,
host: 'translate.google.com',
port: null,
hostname: 'translate.google.com',
hash: null,
search: null,
query: null,
pathname: '/',
href: 'https://translate.google.com/',
retry: {
retries: [Function (anonymous)],
methods: [Set],
statusCodes: [Set],
errorCodes: [Set]
},
headers: {
'user-agent': 'got/9.6.0 (https://github.com/sindresorhus/got)',
'accept-encoding': 'gzip, deflate'
},
hooks: {
beforeRequest: [],
beforeRedirect: [],
beforeRetry: [],
afterResponse: [],
beforeError: [],
init: []
},
decompress: true,
throwHttpErrors: true,
followRedirect: true,
stream: false,
form: false,
json: false,
cache: false,
useElectronNet: false,
agent: TunnelingAgent {
options: [Object],
proxyOptions: [Object],
maxSockets: Infinity,
requests: [],
sockets: [Array],
_events: [Object: null prototype],
_eventsCount: 1,
request: [Function: request],
createSocket: [Function: createSecureSocket],
defaultPort: 443
},
method: 'GET',
forceRefresh: true
}
}
另外,刚才测试中出现 translate is not a function 错误。 改为 import { translate as trans_bing } from 'bing-translate-api'; 用 trans_bing 就没错了。遇到过这种问题吗?
暂时没有遇到,也许是其他地方声明了同名变量被覆盖了。
大量并发的情况还没有测试过,不过毕竟是 free to use, 还是建议控制请求频率。
是不是匿名已经无法使用了呢?