node-google-spreadsheet icon indicating copy to clipboard operation
node-google-spreadsheet copied to clipboard

makeFeedRequest with GZIP throws Error: "incorrect header check"

Open cwolf22 opened this issue 7 years ago • 7 comments

Running the document.getInfo(function(err, data) {}) function is resulting in an exception being thrown by browserfy-zlib. This can be traced back to the request from the makeFeedRequest() function. makeFeedRequest specifies gzip: true in the request, which is causing the failure. Manually removing gzip:true resultings in the api working as expected. Below is how i am utizliing the google-spreadsheets api.

I have a the following wrapper API to turn the callbacks into promises:

const GoogleSheetsAPI = () => {
    return {
        authorize: (sheetsId, credentials) => new Promise((resolve, reject) => {
            if (typeof credentials == 'undefined') {
                credentials = require(CREDENTIALS_PATH)
            }
            const doc = new GoogleSpreadsheet(sheetsId);
            doc.useServiceAccountAuth(credentials, (err) => {
                if (err) reject(err);
                resolve(doc);
            });
        }),
        load: (doc) => new Promise((resolve, reject) => {
            console.log('getting doc info')
            doc.getInfo(function(err, data) {
                if (err) reject(err);
                resolve(data);
            });
        })
    }
}

`

And call this later by:

      gsheetsAPI.authorize(sheetId);
            .then(doc => gsheetsAPI.load(doc))
            .then(data => {
                   //DO STUFF
             })
            .catch(err => console.log(err))

cwolf22 avatar Feb 12 '19 15:02 cwolf22

Hello, I was having this same problem. I have a web app that was tested and working using this package. It recently broke -- not sure if it was last months package update, or that Google updated their Sheets API from v3 to v4.

Regardless, I'm using React with Express middleware. I added the following to set compression headers to false. After doing so, my web app works again.

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

const port = process.env.PORT || 5000;

app.listen(port, function() {
  console.log('Listening on port ' + port + '...');
  function addHeader() { // set if not set by end of request
    if (!this.getHeader('gzip')) {
      this.setHeader('gzip', 'false') // turn off gzip compression
    }
    if (!this.getHeader('Accept-Encoding')) {
      this.setHeader('Accept-Encoding', 'identity') // turn off all compression
    }
  }
}

jwhiteaei avatar Feb 25 '19 15:02 jwhiteaei

@cwolf22 Were you able to track down this error?

gabygarro avatar Aug 14 '19 00:08 gabygarro

No, I'm still using the fix described earlier.

jwhiteaei avatar Aug 14 '19 13:08 jwhiteaei

Getting the same error on a Vue JS application. Made a PR to fix this issue.

fredski02 avatar Sep 03 '19 12:09 fredski02

should be fixed!

theoephraim avatar Sep 03 '19 15:09 theoephraim

For anyone looking for how to get it to work: Initialize the doc like this const doc = new GoogleSpreadsheet('<Spreadsheet ID>', null, { gzip: false })

laurenzcodes avatar Sep 13 '19 15:09 laurenzcodes

Thanks a lot!, now it's working fine !

For anyone looking for how to get it to work: Initialize the doc like this const doc = new GoogleSpreadsheet('<Spreadsheet ID>', null, { gzip: false })

gwendorff avatar Dec 09 '19 22:12 gwendorff