# Error encountered in HTTPs Outcalls

**URL:** <https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390>\
**Category:** Developers\
**Created:** [November 3, 2023, 12:19pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390 "2023-11-03T12:19:56Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 3, 2023, 12:19pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/1 "2023-11-03T12:19:56Z")

</div>

I deployed a canister on the IC that implements HTTP Outcalls. The method appeared to function correctly for several days, but today it returned an error when I executed it.  
`opt "Rejection code 2, Canister http responses were different across replicas, and no consensus was reached";`

Additionally, I encountered an error on the local replica today, despite all tests passing previously.  
`"Rejection code 1, Http body exceeds size limit of 785 bytes.";`  
I also tried to increase the `max_response_bytes` by `2000` but an error remains the same `"Rejection code 1, Http body exceeds size limit of 2785 bytes.";`

---

<div class="post-metadata">

**Author:** ![yotam](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@yotam](https://forum.dfinity.org/u/yotam)\
**Post date:** [November 3, 2023, 12:57pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/2 "2023-11-03T12:57:41Z")

</div>

For the first error, it sounds like, as written, the response is not deterministic or not correctly transformed. The outcall is going out from multiple node machines. Each one then applies the transform function on the response it gets. The transformed response must be exactly the same on all nodes. So you must make sure it is the case.

For the other error, it sounds like the responses are also too big. Do you know what size you actually expect there?

---

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 3, 2023, 1:10pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/3 "2023-11-03T13:10:59Z")

</div>

The response size is less than 1,000 bytes.

My main concern is that I have not made any changes to my code, and it is working correctly on both networks. All tests are also passing. However, today I received these errors:

---

<div class="post-metadata">

**Author:** ![yotam](https://avatars.discourse-cdn.com/v4/letter/y/c0e974/32.png) [@yotam](https://forum.dfinity.org/u/yotam)\
**Post date:** [November 6, 2023, 7:29am UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/4 "2023-11-06T07:29:36Z")

</div>

Could you try to provide more information?  
With the existing information, it is very hard to tell what is going on…

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [November 7, 2023, 6:01pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/5 "2023-11-07T18:01:13Z")

</div>

For the second error, perhaps you didn’t send enough cycles?

---

<div class="post-metadata">

**Author:** ![luckerninja](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/luckerninja/32/12442_2.png) [@luckerninja](https://forum.dfinity.org/u/luckerninja)\
**Post date:** [November 8, 2023, 6:05pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/6 "2023-11-08T18:05:32Z")

</div>

I’m experiencing the same issue with version 0.17.1, but with the message ‘“Rejection code 1, Http body exceeds size limit of 3094 bytes.”’ I’ve attempted to add more loops and increase the ‘max\_response\_bytes’, but the error persists. The file where this error occurs can be found here — [https://github.com/relinkd/ICP-Wallet-Scorer/blob/main/src/params/poap.ts](https://github.com/relinkd/ICP-Wallet-Scorer/blob/main/src/params/poap.ts). Are there any limitations in Azle regarding the maximum response size? Does version 18 differ in this regard?

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [November 8, 2023, 9:21pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/7 "2023-11-08T21:21:20Z")

</div>

There shouldn’t be any in Azle, and I don’t think it should matter from 0.17.x to 0.18.x

Rejection code 1 is a SysFatal error, there’s something wrong at the “system” level it seems. I’m not sure what limit you’re hitting, @ulan do you know who would know the low level details of http outcalls?

---

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 9, 2023, 9:37am UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/8 "2023-11-09T09:37:15Z")

</div>

I am making HTTP requests to the [API](https://deces.matchid.io/deces/api/v1/version). The response size is 139 bytes, and I’m sending 100M cycles for this call. It appears that this API is functioning correctly on both networks. However, a few days ago, it encountered an error.

---

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 9, 2023, 9:48am UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/9 "2023-11-09T09:48:04Z")

</div>

It has come to my attention that when I include a `User-Agent` header, the method works properly (although I haven’t tested this on the mainnet yet, only locally). However, I’m uncertain whether adding this header is necessary, as it was functioning correctly without it a few days ago.

---

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 13, 2023, 8:46am UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/10 "2023-11-13T08:46:29Z")

</div>

This error persists on Mainnet  
@yotam @ulan

---

<div class="post-metadata">

**Author:** ![tim1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tim1/32/6935_2.png) [@tim1](https://forum.dfinity.org/u/tim1)\
**Post date:** [November 13, 2023, 7:54pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/11 "2023-11-13T19:54:51Z")

</div>

I was able to reproduce the issue locally and on small testnet. It seems that without the `User-Agent` header the response has status 403 (forbidden) and a non-deterministic body. When I set the `User-Agent` header to, for example, `my-agent/1.0` it seems to work.

Do I understand correctly that in your case the issue persisted on mainnet when setting a valid `User-Agent` header?

If yes can you give me the following details such that I can try to reproduce on mainnet:

- Subnet your canister is deployed to.
- `dfx` version used when deploying.
- Specific `User-Agent` used to do the requests.

---

<div class="post-metadata">

**Author:** ![zohaib29](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zohaib29/32/29625_2.png) [@zohaib29](https://forum.dfinity.org/u/zohaib29)\
**Post date:** [November 13, 2023, 8:38pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/12 "2023-11-13T20:38:21Z")

</div>

When I add the `User-Agent` Header the HTTP outcalls work locally, but on IC it fails  
So for Mainnet, I removed all headers while making a `GET` request.

However, I’m encountering an issue where the result does not consistently persist with each call.

1. Sometimes it works fine
2. Sometimes it results `"Rejection code 2, Canister http request timed out"`
3. Sometimes it results ` "Rejection code 2, Canister http responses were different across replicas, and no consensus was reached"`

- Subnet the canister deployed to [4ecnw-byqwz-dtgss-ua2mh-pfvs7-c3lct-gtf4e-hnu75-j7eek-iifqm-sqe](https://dashboard.internetcomputer.org/subnet/4ecnw-byqwz-dtgss-ua2mh-pfvs7-c3lct-gtf4e-hnu75-j7eek-iifqm-sqe)
- DFX Version: 0.15.1

---

<div class="post-metadata">

**Author:** ![tim1](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/tim1/32/6935_2.png) [@tim1](https://forum.dfinity.org/u/tim1)\
**Post date:** [November 13, 2023, 9:27pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/13 "2023-11-13T21:27:08Z")

</div>

I think issue 3 is caused by the API returning a 429 error when too many requests are made, and in this case, the response is non-deterministic. You can see in the script below that the hash differs for status 429. To gracefully handle this you could prune the body in the transform function for status code 429.

```auto
for i in {1..100}; do curl -s -o response.txt -w "%{http_code}" https://deces.matchid.io/deces/api/v1/version; echo -n " "; sha256sum response.txt | awk '{print $1}'; done

```

Issue 2 seems to be a connectivity issue between the IC nodes and [matchid.io](http://matchid.io). How often does this occur compared to issues 1 and 3? Both kinds of errors are common for public APIs that have stricter rate limits, so I would suggest ensuring that your calling logic limits in-flight requests and implements a backoff strategy for failed requests.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [November 30, 2023, 10:24pm UTC](https://forum.dfinity.org/t/error-encountered-in-https-outcalls/24390/14 "2023-11-30T22:24:44Z")

</div>

@luckerninja Does any of this solve your problems?
