简体   繁体   中英

Fetch request failing in google apps script ONLY

I am trying to setup a google chat app that sends information to my server, however I am running into a problem where the request fails with a 464 error only when using Google Apps script. Running the request in a browser using axios or fetch, or using my own client, or using postman, this same request works 100% of the time without fail. But as soon as I make this request from google apps script it results in a 464 and I cannot figure out why.

The code itself is quite simple here it is in google script:

const response = UrlFetchApp.fetch('https://dev-core.kalosflorida.com/v1/trelloslackbot', 
{ 
  method: "GET",
  followRedirects: true, 
  muteHttpExceptions: true
})

and in standard javascript

fetch('https://dev-core.kalosflorida.com/v1/trelloslackbot')
  .then(res => console.log(res))
  .catch(err => console.error(err))

I can see no difference between the two examples but the google script version always fails with a 464 error at my load balancer.

The error is explained in Amazon's troubleshooting guide :

HTTP 464 The load balancer received an incoming request protocol that is incompatible with the version config of the target group protocol.

Possible causes:

  • The request protocol is an HTTP/1.1, while the target group protocol version is a gRPC or HTTP/2.
  • The request protocol is a gRPC, while the target group protocol version is an HTTP/1.1.
  • The request protocol is an HTTP/2 and the request is not POST, while target group protocol version is a gRPC.

In your case, the issue appears to be the first one. Your load balancer's target group protocol is HTTP/2 , while Apps Script sends an HTTP/1.1 request.

You can test this with the HTTP2.Pro API :

function test() {
  const response = UrlFetchApp.fetch('https://http2.pro/api/v1')
  console.log(response.toString())
}

This API returns the protocol used as a JSON string. In Apps Script the response is something like this:

{
   "http2":0,
   "protocol":"HTTP\/1.1",
   "push":0,
   "user_agent":"Mozilla\/5.0 (compatible; Google-Apps-Script; beanserver; +https:\/\/script.google.com; id: [...])"
}

Meanwhile accessing the endpoint in the browser with Javascript or just entering the URL will return the following:

{
   "http2":1,
   "protocol":"HTTP\/2.0",
   "push":1,
   "user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/100.0.4896.127 Safari\/537.36"
}

As you can see, Google's Apps Script server sends an HTTP/1.1 request while your browser will use HTTP/2 . I went over the UrlFetchApp documentation and it doesn't look like there's a way to change the protocol used by Apps Script so you may have to configure your load balancer's target groups to use HTTP/1.1 instead. Amazon has some relevant documentation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM