Giter Club home page Giter Club logo

mstranslator's Issues

ArgumentException: The Web Token must have a signature at the end.

Hi.

I'm getting the error

ArgumentException: The Web Token must have a signature at the end. The incoming token did not have a signature at the end of the token. : ID=6346.V2_Json.Translate.4B2C3363

The code I'm using is

var express = require('express');
var app = express();

var server = app.listen(3000,function(){
  var host = server.address().address;
  console.log(host);
  var port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});

var MsTranslator = require('mstranslator');
  // Second parameter to constructor (true) indicates that
  // the token should be auto-generated.
  var client = new MsTranslator({
    client_id: "mejustme"
    , client_secret: "tM0Zc37RypU3Lqm8WtFH7XXuTAOfkoJZraMz2axEVf4"
  }, true);

  var params = {
    text: 'How\'s it going?'
    , from: 'en'
    , to: 'es'
  };

  // Don't worry about access token, it will be auto-generated if needed.
  client.translate(params, function(err, data) {
        console.log(data);
  });

How could I fix it?

Thank you for the attention.

exception thrown above 4736 characters

When I run your libary with less than 4737 characters, like so:

translate({
    text: article.body.substr(0, 4636),
    from: 'zh-CHS',
    to  : 'en',
})

It works fine. Yet when I run it with 4647 characters or more:

translate({
    text: article.body.substr(0, 4637),
    from: 'zh-CHS',
    to  : 'en',
})

I get an exception:

    [SyntaxError: Unexpected token !]
    SyntaxError: Unexpected token !
        at Object.parse (native)
        at IncomingMessage.<anonymous> (/home/tom/projects/chambeng/chambeng-amt/node_modules/mstranslator/mstranslator.js:116:25)
        at IncomingMessage.emit (events.js:129:20)
        at _stream_readable.js:908:16
        at process._tickCallback (node.js:355:11

And when I inspect the API's response it gives:

    !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
    <HTML><HEAD><TITLE>Bad Request</TITLE>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
    <BODY><h2>Bad Request - Request Too Long</h2>
    <hr><p>HTTP Error 400. The size of the request headers is too long.</p>
    </BODY></HTML>

It seems like this libary should use another HTTP method and/or bundle large requests into several smaller requests.

API errors don't bubble up as errors

For example, calling translate before client is initialized results in the following result string (but no error object):

client.translate(params, function(err, data) {
        if(err) {
            console.log(err);
            return;
        }

        console.log("data: ", data);
    });

"data: ArgumentException: No bearer information found in the token : ID=0818.V2_Json.Translate.467BDC19"

Handle request errors

Hi, thanks for creating this module!
I was having some problems with the connection, giving me an ECONNRESET. I know that it is not a problem of your module, but I think it would be great if you listen for 'error' events, when you create the http / https request, so we can handle them as any other error.

TranslateApiException

Hi @nanek,

I'm having a weird problem were the MS API simply stops recognizing my app. I spin up the server, the translation requests through this lib work as expected and at any time for no reason it stops working.

see the log below. it works and then it starts failing.

/translate { text: 'hola', from: 'es', to: 'en' }
all good in translate Hello
/translate { text: 'hola que tal?', from: 'es', to: 'en' }
all good in translate Hello, how are you doing?
/translate { text: '', from: 'es', to: 'en' }
error in translate [Error: "TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=5005.V2_Json.Translate.2C53805E"]
/translate { text: 'hola', from: 'es', to: 'en' }
error in translate [Error: "TranslateApiException: Cannot find an active Azure Market Place Translator Subscription associated with the request credentials. : ID=3444.V2_Json.Translate.2CB38A02"]

Do you have any idea why this might be happening ?
I couldn't find any useful information related to this error.

VSCode Extension

Hi guys

I have installed this module into my vscode extension, made sure the MSTranslator is required correctly, I have a valid Azure key, but when I run the code I can debug and follow it to client.initialize_token(function(){ line, everything looks ready to go but then it just jumps away, no data is ever console logged.

Perhaps not being able to debug it into the functions is my poor understanding of javascript, but no code is ever called, azure is not called, my dashboard shows no calls are made.

What am I missing here?

Unhandled 'error' event

The application is working, but not rarely I'm getting the following error.

_events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT
at exports.errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect as oncomplete

The code is

var MsTranslator = require('mstranslator');
  // Second parameter to constructor (true) indicates that
  // the token should be auto-generated.
  var client = new MsTranslator({
    client_id: "mejustme"
    , client_secret: "tM0Zc37RypU3Lqm8WtFH7XXuTAOfkoJZraMz2axEVf4="
  }, true);

  var params = {
    text: 'most beautiful place is spain'
    , from: 'en'
    , to: 'es'
  };

  // Don't worry about access token, it will be auto-generated if needed.
  client.translate(params, function(err, data) {
        console.log(data);
  });

Proxy issue

I am working in a university, so I have to write a proxy when I need to access external APIs, I already did that with Wikipedia Api, but how can I provide mstranslator functions with a proxy??

translating sometimes but not consuming quota

Hi, thanks for your great module.

I've just installed it after following all the steps to setup my microsoft translator api, and introduced my client_id and client_secret.

The problem is it randomly traduces the text (about 50% of the times), but without consuming my quota of 2M (and I've used microsoft site to test and consume it (https://datamarket.azure.com/dataset/explore/bing/microsofttranslator). The 50% of the time that fails it gives this error:
The Azure Market Place Translator Subscription associated with the request credentials has zero balance.

Is this any known bug or am I missing something?

Thanks in advance.

Deleting local variable in strict mode

Babel 6 (6.8.0) reports mstranslator.js is attempting to delete a local variable (buffers) at line 177.

node_modules/mstranslator/mstranslator.js: Deleting local variable in strict mode (177:6)
  175 |         index += buf.length;
  176 |       });
> 177 |       delete(buffers);
      |       ^
  178 |       fn(null, body);
  179 |     });
  180 |   });

Process finished with exit code 1

The delete just looks incorrect and it looks like the fix is to remove line 177 (line179 in the current master).

Client side

Hello from frog land !

I use mstranslator and it works thanks for your Api

I use it with nodesjs and no problems.

But my application is web and on browser i would
like use the client credentials rather mine (server side)

I try to use it with client javascript but your api is writen with require and i turn around a solution because of http https querystring modules.

To work with these modules i tried browserify without success.

I don't want a node_modules directory for my web site.
My tree nodesjs is for logical works.

And i have some difficulties to make your very good api running.
Just because of these modules.
With browserify i have errors the output file using require which is looking for the good paths.

So i try to perform my translations without asking to the server nodes to work.
I prefer use the javascript browser side.

Do you have a full client javascript solution ?

Thanks for your attention, have a nice day.

Frog land is also cheese land. In the south it smell

P.s: sorry for my english

Switch testing to Mocha

As mentioned in Expresso, https://github.com/visionmedia/expresso

TDD framework for nodejs. This module is no longer maintained by me, if you wish to maintain it let me know, otherwise use Mocha.

Since it is no longer actively maintained (and fails to install for me), switch to Mocha as suggested.

getLanguageNames throws TypeError: "listener" argument must be a function

This is some quick test code that I wrote to make sure that I was getting the arguments right:
translator.getLanguageNames("en", ["sv", "es", "ru"], console.log);
When I run it, I get this error:

TypeError: "listener" argument must be a function
    at _addListener (events.js:216:11)
    at ClientRequest.addListener (events.js:270:10)
    at MsTranslator.call (C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:150:7)
    at C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:78:19
    at IncomingMessage.<anonymous> (C:\Users\Nick\Desktop\App\node_modules\mstranslator\mstranslator.js:103:9)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:926:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)

Can someone help me here?

Getting error in response instead of in error object : TranslateApiException

err : null
translated_data :TranslateApiException: The Azure Market Place Translator Subscription associated with the request credentials is not in an active state. : ID=3444.V2_Json.TranslateArray.5B6EAD27

Translate.translateArray(params, function(err, translated_data) { //Check if any error found console.log("err : "+err, "translated_data "+translated_data) }

Translating to multiple languages

Hi,

I was wondering if this package can handle translating to multiple languages at once with only one calls. Because as it's up to right now, I have to make multiple calls to translate.

Typo in the readme

Not a big deal, but in your code sample in the readme you have this:

var MsTanslator = require('mstranslator');
var client = new MsTranslator({client_id:"your client_id", client_secret: "your client secret"});

You'll notice on the first line it says MsTanslator (missing first 'r'). When copying and pasting code for first time to kick the tires of the API, I noticed it. Nice work on the API though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.