You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added support for JWT tokens in the headers within the Forta SDK causes the default headers in web3py to be overridden since custom headers, such as the Authorization header, are provided. This results in a bug where the Content-Type header is not set to application/json, leading to issues in RPC calls. The Forta SDK should ensure that the default headers are still passed along with any custom headers.
Steps to Reproduce:
Point the rpc_url to a local EVM-compatible node such as Frontier.
Observe that the default headers in web3py are overridden.
Notice that the Content-Type header is missing, leading to issues in RPC calls.
Expected Behavior:
The SDK should retain the default headers in web3py while adding the JWT token headers to avoid any issues.
Actual Behavior:
The SDK overrides the default headers in web3py, causing issues in RPC calls that require the Content-Type header.
Workaround:
To resolve this issue temporarily, include the Content-Type header explicitly in the rpc_headers parameter as shown below:
asyncdefmain():
"""This function is the entry point"""initialize_response=awaitinitialize()
awaitasyncio.gather(
scan_ethereum({
'rpc_url': EVM_RPC,
'handle_transaction': handle_transaction,
'rpc_headers': {
"Content-Type": "application/json"
}
}),
run_health_check()
)
Debugging Details:
The issue appears as a 415 Unsupported Media Type error when using an EVM-compatible node such as Frontier, which does not occur when using Cloudflare's public ETH node.
The error traceback is as follows:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/forta_bot_sdk/utils/with_retry.py", line 35, in with_retry
response = await fn(*args)
File "/usr/local/lib/python3.10/site-packages/web3/providers/async_rpc.py", line 91, in make_request
raw_response = await async_make_post_request(
File "/usr/local/lib/python3.10/site-packages/web3/_utils/request.py", line 239, in async_make_post_request
response = await async_get_response_from_post_request(
File "/usr/local/lib/python3.10/site-packages/web3/_utils/request.py", line 232, in async_get_response_from_post_request
response = await session.post(endpoint_uri, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 693, in _request
resp.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1058, in raise_for_status
raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 415, message='Unsupported Media Type', url=URL('http://alice:9944')
Mitmproxy request logs show that the content-type header is being set to application/octet-stream instead of application/json:
Additional Context:
This issue causes significant inconvenience as it requires users to manually set the Content-Type header, which is not intuitive. A fix to retain default headers while supporting JWT would greatly improve the developer experience.
The text was updated successfully, but these errors were encountered:
Added support for JWT tokens in the headers within the Forta SDK causes the default headers in web3py to be overridden since custom headers, such as the
Authorization
header, are provided. This results in a bug where theContent-Type
header is not set toapplication/json
, leading to issues in RPC calls. The Forta SDK should ensure that the default headers are still passed along with any custom headers.Steps to Reproduce:
rpc_url
to a local EVM-compatible node such as Frontier.Content-Type
header is missing, leading to issues in RPC calls.Expected Behavior:
The SDK should retain the default headers in web3py while adding the JWT token headers to avoid any issues.
Actual Behavior:
The SDK overrides the default headers in web3py, causing issues in RPC calls that require the
Content-Type
header.Workaround:
To resolve this issue temporarily, include the
Content-Type
header explicitly in therpc_headers
parameter as shown below:Debugging Details:
application/octet-stream
instead ofapplication/json
:Relevant Code: forta-bot-sdk-v2/py-sdk/src/forta_bot_sdk/scanning/evm/get_provider.py
Environment:
forta_bot_sdk
0.2.3Additional Context:
This issue causes significant inconvenience as it requires users to manually set the
Content-Type
header, which is not intuitive. A fix to retain default headers while supporting JWT would greatly improve the developer experience.The text was updated successfully, but these errors were encountered: