Query keeps failing when executed from script

I have a query that keeps failing with 502 when I execute it from a script. It currently is set to process values in 30 batches, but it was working with 500 batches before. If I run the same on the graphical interface is works fine. Can you please check why is this happening? Is this a timeout maybe?

    {
      ethereum(network: bsc) {
        address(
          address: {in: ["0x0f954e4b6fc09bf87528924527306b209f2b329d", "0xb241b05f3066c3dc34eba34745d9950a84f1ce0b", "0x007ace5397b56e19a9436fba289d7fed71c49328", "0x57c4195c0e07e8a37b58b52ef9d57d1adcf8e71e", "0xd3f478f0d5e98b01f757bc6cb54db4c00b9838f2", "0xc760f87e4bd0aac44fb0b90833836e2e9051e506", "0xa17d2c8b629095672633828d744a03608bbaae24", "0xfff58a50fdde55f5b5626bb66de476f63155e078", "0x40d91625aed59257132495f01f073e7c2084cf7f", "0xb450cbf17f6723ef9c1bf3c3f0e0aba368d09bf5", "0x3027ad7781700a03496613377152dba78c38fa55", "0x02bff262b10b7ae1d2e4455ad4cae2d0a6ecf086", "0x2407a09d25f8b72c8838a56b4100ce600fbfa4ed", "0x0e2c2f05ee62010afdac23f11608ad68ad1ddcec", "0x2941273449ab4eb6fcdf8f84763f017fae264091", "0x591d849595ba76ea4fa61c4f5c86c484d18abf43", "0x3962d641f3c6afe676c7b7fbd088b0071c9b0dff", "0x58f876857a02d6762e0101bb5c46a8c1ed44dc16", "0xc87678ed091b52e03146d7e75a99222c9319f9e5", "0x2d9b4109ed85f40ef2fbfaa16539c7b156974da3", "0x90b4320d89abc65b7129043000db6c1ecd7e24e6", "0xad7db2aea6e8904347be097f920174469a64774e", "0x17cdfd9fa93b42670c7c529f9c7bd22d11c8cbe2", "0xce22fc73892d9b4c2b6ff1b9b46a3c61b879bc11", "0x2edb318d3af9424d434576860686a3bb9d04cca7"]}
        ) {
          balances(currency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}) {
            currency {
              symbol
              address
            }
            value
          }
          address
        }
      }
    }

502 - Query taking too much time to process hence not able to return results in given time and request getting timeout.

To solve this you need to optimize the query.

use date filter or height filter, basically making a query to process fewer data to return results.

For example in the following example - I added a height filter

{
  ethereum(network: bsc) {
    address(
      address: {in: ["0x0f954e4b6fc09bf87528924527306b209f2b329d", "0xb241b05f3066c3dc34eba34745d9950a84f1ce0b", "0x007ace5397b56e19a9436fba289d7fed71c49328", "0x57c4195c0e07e8a37b58b52ef9d57d1adcf8e71e", "0xd3f478f0d5e98b01f757bc6cb54db4c00b9838f2", "0xc760f87e4bd0aac44fb0b90833836e2e9051e506", "0xa17d2c8b629095672633828d744a03608bbaae24", "0xfff58a50fdde55f5b5626bb66de476f63155e078", "0x40d91625aed59257132495f01f073e7c2084cf7f", "0xb450cbf17f6723ef9c1bf3c3f0e0aba368d09bf5", "0x3027ad7781700a03496613377152dba78c38fa55", "0x02bff262b10b7ae1d2e4455ad4cae2d0a6ecf086", "0x2407a09d25f8b72c8838a56b4100ce600fbfa4ed", "0x0e2c2f05ee62010afdac23f11608ad68ad1ddcec", "0x2941273449ab4eb6fcdf8f84763f017fae264091", "0x591d849595ba76ea4fa61c4f5c86c484d18abf43", "0x3962d641f3c6afe676c7b7fbd088b0071c9b0dff", "0x58f876857a02d6762e0101bb5c46a8c1ed44dc16", "0xc87678ed091b52e03146d7e75a99222c9319f9e5", "0x2d9b4109ed85f40ef2fbfaa16539c7b156974da3", "0x90b4320d89abc65b7129043000db6c1ecd7e24e6", "0xad7db2aea6e8904347be097f920174469a64774e", "0x17cdfd9fa93b42670c7c529f9c7bd22d11c8cbe2", "0xce22fc73892d9b4c2b6ff1b9b46a3c61b879bc11", "0x2edb318d3af9424d434576860686a3bb9d04cca7"]}
    ) {
      balances(height: {gteq: 8253000}
        currency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}) {
        currency {
          symbol
          address
        }
        value
      }
      address
    }
  }
}

is there a way to set the block height automatically or maybe give it a timestamp so I do not have to manually update this every time?

You can set it programmatically … right?

Ok but if I use the latest block height it keeps failing, it will take a day or 2 to start working again so obviously using the last block height is not working so I need to go back a little bit, but kind of unsure how long. Also do we have a query for the last block height?

Is this solved? If not please DM me on Telegram @gaurav_zen