Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request path contains unescaped characters #2046

Closed
dsaumyajit007 opened this issue Jan 29, 2016 · 17 comments
Closed

Request path contains unescaped characters #2046

dsaumyajit007 opened this issue Jan 29, 2016 · 17 comments

Comments

@dsaumyajit007
Copy link

I am trying to make a simple GET request to a website : https://www.crunchbase.com/location/belgrade/2a22cd01619e1ff39394303b255670cb?utm_source=crunchbase_tc_river&utm_medium=export&utm_campaign=dataset

I get an error such as this :

throw new TypeError('Request path contains unescaped characters.');
    ^

TypeError: Request path contains unescaped characters.
    at new ClientRequest (_http_client.js:53:11)
    at TunnelingAgent.exports.request (http.js:31:10)
    at TunnelingAgent.createSocket (/usr/lib/nodejs/tunnel-agent/index.js:117:25)
    at TunnelingAgent.createSecureSocket [as createSocket] (/usr/lib/nodejs/tunnel-agent/index.js:184:41)
    at TunnelingAgent.addRequest (/usr/lib/nodejs/tunnel-agent/index.js:80:8)
    at new ClientRequest (_http_client.js:137:16)
    at Object.exports.request (http.js:31:10)
    at Object.exports.request (https.js:181:15)
    at Request.start (/usr/lib/nodejs/request/index.js:607:30)
    at Request.end (/usr/lib/nodejs/request/index.js:1235:28)

Is there any fix to check if the url is compatible to be sent in the request function as a paramater ? I am using request@2.51.0 and node v5.5.0

@SimonSchick
Copy link

Works fine when I do it, using same versions as you:

'use strict';

const request = require('request');

request(
    'https://www.crunchbase.com/location/belgrade/2a22cd01619e1ff39394303b255670cb?utm_source=crunchbase_tc_river&utm_medium=export&utm_campaign=dataset',
    (error, response, body) => {
        if (error) {
            return console.error(error);
        }
        return console.log(body.substr(0, 128) + '...');
    }
);

Can you post your code?

@SimonSchick
Copy link

I looked into the actual error.
This error can only occur when you snuck a whitespace into the url, I tried to to this but request always seems to escape those correctly.
You'll have to post a snippet, or try a newer version (yours is quite old) and see if the error persists.

@dsaumyajit007
Copy link
Author

I work behind a proxy server. Your code does not seem to work behind a proxy. I am pasting my code below. Could you please tell me whether this is the correct way of sending a request while working behind a proxy server.

'use strict';

const request = require('request');


var get_config = function(site_url){
    var config = {
        url : ((site_url)),
        proxy : 'http://proxyhost:proxyport'
    };

    return config;
};
request(
    get_config('https://www.crunchbase.com/location/belgrade/2a22cd01619e1ff39394303b255670cb?utm_source=crunchbase_tc_river&utm_medium=export&utm_campaign=dataset'),
    (error, response, body) => {
        if (error) {
            return console.error(error);
        }
        return console.log(body.substr(0, 128) + '...');
    }
)

Also an interesting observation is that when I am replacing "https" with "http", the request is working properly.

@SimonSchick
Copy link

Your proxy doesn't support https then?

@SimonSchick
Copy link

From what I can tell, internally there is some redirect happening, but the redirect seems to have a malformed/bad URL that contains whitespaces, that ticks off this error.

If it is a public proxy, could you please post the info?
If not, please add a breakpoint at "/usr/lib/nodejs/request/index.js:607" and inspect the passed url via any debugger.

@sudheesh001
Copy link

Hey @dsaumyajit007

This looks fine and works perfectly with google.com, result after your code snippet.

const request = require('request');


var get_config = function(site_url){
    var config = {
        url : ((site_url)),
        proxy : 'http://proxyurl:proxyport'
    };

    return config;
};
request(
    get_config('https://www.crunchbase.com/location/belgrade/2a22cd01619e1ff39394303b255670cb')
    , (function (error, response, body) {
        console.log(response.statusCode);
        console.error(error);
        return console.log(body.substr(0, 128) + '...');
    })
);

For google.com

200
null
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-IN"><head><meta content="text/html; charset=UTF-...

@SimonSchick
Copy link

@sudheesh001 Please note that you might be using a different proxy.
Lets wait for him.

@dsaumyajit007
Copy link
Author

I have a very basic doubt : I am running Node js on Ubuntu 14.04 and on running
node --version
I get v5.5.0 . Is this the most stable release because somewhere I saw that the releases are 0.x.x . Am i using the right version of Node? I installed it as per the instructions on https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

@SimonSchick
Copy link

Yes, the 0.x releases are from before the iojs/nodejs merge.
v5.5.0 is stable.

I still believe it's just your proxy being weird.

@dsaumyajit007
Copy link
Author

Ok. Any reason why the link works on repacing "https" with "http" ? It fixes this issue somehow

@SimonSchick
Copy link

#2046 (comment)

@dsaumyajit007
Copy link
Author

Ok Its magically working now. 👍
I just reinstalled nodejs and the request package. Thanks for all the help @sudheesh001 @SimonSchick

@simov simov closed this as completed Feb 5, 2016
@SashaDesigN
Copy link

I reinstall request module but it fails after few days to this error agian

@ish3lan
Copy link

ish3lan commented Oct 1, 2018

I had the same problem, wonder if people complaining here have another language activated in their keyboards? I do have arabic/english. this might takes us somewhere while investigating

@sgb-io
Copy link

sgb-io commented Mar 3, 2019

I am experiencing this issue on windows (ethernet to home network) but not on macOS (wifi to same network). The http trick does not work for me.

@TsPuujee
Copy link

TsPuujee commented May 23, 2019

let url = 'http://localhost:30001?q=ааббввггдд'
axios.get(encodeURI(url)).then( data => { })

@yang-o
Copy link

yang-o commented Jul 19, 2019

在kubernetes环境使用request发送get请求,url中携带中文参数时会发生这个错误,在其他环境则不会

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants