-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
local_filter_middleware example doesn't work #1244
Comments
The doc example shouldn't have the parentheses. It should be: from web3.middleware import local_filter_middleware
w3.middleware_onion.add(local_filter_middleware) |
@jgeary What issue did you have? Im not getting an error adding the middleware this way.
|
@dylanjw thanks for getting back about this. im using an asyncio event loop to watch for new events from multiple different filters in a continuous loop, and it seems like this middleware isn't compatible with that. here is what im working with: (modified to make it more generic and ignore unnecessary bits):
when i run this script without installing the local filter middleware, it smoothly prints old and new entries. the only issue is it fails every now and then after the node deletes my filters. in production im using a process manager that restarts it after it fails, and the other services dependent on this service are not affected by the redundancy. so this isn't crucial, but i would prefer to use the local filter middleware. but when i run this script as it is above, it hangs for a while (and mysteriously sometimes prints out a single
|
The function post_event_loop is missing the Needs to be: async def post_event_loop(event_filter, name): Maybe that is just a typo obfuscating the original issue. If so, can you post the traceback once you have the async keyword added? |
@dylanjw good catch, but i actually already had the |
Can you try to reduce your code to the simplest broken example? What happens when you run a synchronous version of You can try setting the environment variable |
cleaning up stale issues; please reopen/open a new one if appropriate. |
What was wrong?
I upgraded from 4.8.2 to 5.0.0a5 to use the local filter middleware so I don't have to deal with the node deleting my filters. Unfortunately, I've been unable to use
local_filter_middleware
, which I believe is due to incorrect / lacking documentation.According to the docs, here is the proper usage of
local_filter_middleware
:When I do this, I get the error
local_filter_middleware() missing 2 required positional arguments: 'make_request' and 'w3'
. Sure enough, the middleware does require those 2 arguments (source). There are no docs or even tests from the related PR (#732) that ever calllocal_filter_middleware
withw3
ormake_request
. I have no idea what to pass in formake_request
. I found it odd that I was callinglocal_filter_middleware()
at all, butmiddleware_onion.add(local_request_middleware)
doesn't work either.How can it be fixed?
Please let me know what arguments I'm supposed to pass into
local_filter_middleware()
, and consider editing the relevant documentation for the next release so others don't need to ask.The text was updated successfully, but these errors were encountered: