It looks like message port closed before a response was received
often comes from Browser extension, e.g., see Chrome: "The message port closed before a response was received." · Issue #130 · mozilla/webextension-polyfill · GitHub.
However, I don’t expect that this is causing the issue here. I recommend looking at the network tab in your browser’s dev tools (your screenshot is from the console). If you see the request and the response contains the contracts you expect, then you can be sure that the issue is somewhere in the filtering you do afterwards.
Looking at your code, it seems like you might be running into a similar issue as in How to successfully create a contract using python request lib?. templateId
is a string of the form packageid:modulename:entityname
. So if you want to get the module name you’ll have to do something like contract.templateId.split(":")[1]
and contract.templateId.split(":")[2]
for the entity name (ideally only split once).