Skip to content

Unescaped Characters when using languages other than English in Node JS?

I am using a Google cloud function with the Google Places API. It works fine in English, but I get this error when inputting Hebrew or Russian:

Unhandled error TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

When I try my request directly in a web browser it works fine:основной

But when I try the exact same string in NodeJS I get the error above, here is my code (I tried unescape):

var input = unescape(data.textInput); //string
var key = "myKey";
var type = "address";
var url = "" + "key=" + key + "&type=" + type + "&input=" + input;


Try to encode the url before performing the actual request.

var url = "" + "key=" + key + "&type=" + type + "&input=" + input;
var encodedUri = encodeURI(url)