javascriptnode.jsnode-request

Simple request returning error code ERR_UNESCAPED_CHARACTERS on a specific URL


Summary

The URL https://www.eponuda.com/graficke-kartice-cene/gigabyte-radeon-rx-6900-xt-16gb-gddr6-2‎56-bit-gv-r69xtgaming-oc-16gd-graficka-kartica-cena-579068 returns error below, but other URLS return expected HTML body, like for example https://www.eponuda.com/graficke-kartice-cene/asus-geforce-dual-gaming-rtx-3060-12gb-ddr6-192bit-dual-rtx3060-12g-graficka-kartica-cena-609076. I am clueless as to what causes the issue.

Code

const options = {
    url: 'https://www.eponuda.com/graficke-kartice-cene/gigabyte-radeon-rx-6900-xt-16gb-gddr6-2‎56-bit-gv-r69xtgaming-oc-16gd-graficka-kartica-cena-579068',
    method: 'GET'
};

request(options, (error, response, body) => {
  console.error('error:', error); 
  console.log('statusCode:', response && response.statusCode); 
  console.log('body:', body); 
});

Console

TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

Environment

software version
request 2.88.2
node 14.15.5
npm 6.14.11
Operating System Windows 10

Solution

  • try encoding the url like this

    url: encodeURI('https://www.eponuda.com/graficke-kartice-cene/gigabyte-radeon-rx-6900-xt-16gb-gddr6-2‎56-bit-gv-r69xtgaming-oc-16gd-graficka-kartica-cena-579068')