first argument must be a string of Buffer

See original GitHub issue

Hi, I was running some code and got this error message:

_http_outgoing.js:441
    throw new TypeError('first argument must be a string or Buffer');
    ^

TypeError: first argument must be a string or Buffer
    at ClientRequest.OutgoingMessage.write (_http_outgoing.js:441:11)
    at Request.write (/Users/tomasnovella/workspace/kitt/kitt-chrome-sync/node_modules/request/request.js:1392:25)
    at end (/Users/tomasnovella/workspace/kitt/kitt-chrome-sync/node_modules/request/request.js:550:16)
    at Immediate._onImmediate (/Users/tomasnovella/workspace/kitt/kitt-chrome-sync/node_modules/request/request.js:578:7)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Funny thing is, that if I replace the current version of request module with an older one(### v2.60.0 (2015/07/21), according to changelog), everything works just fine.

The code that causes this error is this:

  request.post({
        url: '<someURL>',
        qs: {
          'client': 'Google+Chrome',
          'client_id': config.clientId
        },
        headers: {
          'Content-Type': 'application/octet-stream',
          'Authorization': 'Bearer '+ accessToken
        },
        encoding: null, //  if you expect binary data
        responseType: 'buffer', 
        body: body
    }, (error, response, body) => {..blah...});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:8
  • Comments:26 (9 by maintainers)

github_iconTop GitHub Comments

29reactions
cozzbiecommented, Sep 10, 2016

Basically do not use body: {} in your request. If you want to pass data in the body, use json: {} instead

22reactions
simovcommented, Apr 22, 2016

Set the json option to true, also take a look at the options section in the docs. Your last question is not related to this issue, post a new one if you have other questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - nodejs - first argument must be a string or Buffer
I'm simply trying to create a node server that outputs the HTTP status of a given URL. When I try to flush the...
Read more >
Error when adding file: "TypeError: First argument must be a ...
When calling the add function, I'm getting the following error: TypeError: First argument must be a string or Buffer My service class ...
Read more >
Getting the following error throw new TypeError('First ...
Getting the following error throw new TypeError('First argument must be a string of Buffer'); (Example) | Treehouse Community.
Read more >
The first argument must be one of type string or Buffer. - Reddit
Hello to everyone. I'm trying to follow a course about how to create a 3D multi-player game and he says to execute this...
Read more >
ERROR: The first argument must be of type string or an ...
ERROR: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found