Skip to content
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

Candid Interface for Canisters - Cannot find field "principal" #88

Open
kylelangham opened this issue Dec 2, 2022 · 2 comments
Open
Assignees

Comments

@kylelangham
Copy link

kylelangham commented Dec 2, 2022

Hi,

I'm receiving a "cannot find field 'principal' when I run the below code. It seems like the candid did is incorrect, but I've verified it multiple times. Any suggestions on troubleshooting? Thanks!

--------------------------------CODE---------------------------------
from ic.canister import Canister
from ic.client import Client
from ic.agent import Agent
from ic.candid import encode, decode, Types
from ic.identity import Identity

i1 = Identity()
client = Client(url = "https://ic0.app")
agent = Agent(i1, client)

params = []
params = encode(params)

canister_id = 'zqfso-syaaa-aaaaq-aaafq-cai'

response = agent.query_raw(canister_id,'__get_candid_interface_tmp_hack',params)
canister_did = response[0]['value']
canister = Canister(agent=agent, canister_id=canister_id, candid=canister_did)
---------------------------------------ERROR----------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\SNS\test.py", line 20, in
my_canister.list_neurons({ 'of_principal': [], 'limit': 1000, 'start_page_at': []})
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\canister.py", line 57, in call
res = self.agent.query_raw(
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\agent.py", line 79, in query_raw
return decode(result['reply']['arg'], return_type)
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 1297, in decode
'value': t.decodeValue(b, types[i])
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 671, in decodeValue
x[expectKey] = exceptValue.decodeValue(b, v)
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 552, in decodeValue
rets.append(self._type.decodeValue(b, vec._type))
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 859, in decodeValue
return self._type.decodeValue(b, t)
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 671, in decodeValue
x[expectKey] = exceptValue.decodeValue(b, v)
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 552, in decodeValue
rets.append(self._type.decodeValue(b, vec._type))
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 859, in decodeValue
return self._type.decodeValue(b, t)
File "C:\Users\KyleLangham\PycharmProjects\ICPTransactions\venv\lib\site-packages\ic\candid.py", line 674, in decodeValue
raise ValueError("Cannot find field {}".format(keys[idx]))
ValueError: Cannot find field "principal"

Process finished with exit code 1

@Myse1f
Copy link
Contributor

Myse1f commented Dec 3, 2022

This should be fix in #74 . Later we release a new version. Or you can use the main branch in repository.

@4eku
Copy link

4eku commented Feb 11, 2023

I observe a similar problem with some queries. For example code:

import asyncio
from ic.canister import Canister
from ic.client import Client
from ic.identity import Identity
from ic.agent import Agent
from ic.candid import Types

iden = Identity()
client = Client()
agent = Agent(iden, client)
governance_did = open("governance.did").read()
governance = Canister(agent=agent, canister_id="zqfso-syaaa-aaaaq-aaafq-cai", candid=governance_did)
async def async_test():
  res = await governance.list_neurons_async(
    {
        'of_principal': [],
        'limit': 1,
        'start_page_at': []
    }
  )
  print(res)
asyncio.run(async_test())

Executing this code gives the same error as Kyle's.
And if you use a different canister method - everything is ok:

import asyncio
from ic.canister import Canister
from ic.client import Client
from ic.identity import Identity
from ic.agent import Agent
from ic.candid import Types

iden = Identity()
client = Client()
agent = Agent(iden, client)
governance_did = open("governance.did").read()
governance = Canister(agent=agent, canister_id="zqfso-syaaa-aaaaq-aaafq-cai", candid=governance_did)
async def async_test():
  res = await governance.list_proposals_async(
    {
        'include_reward_status': [],
        'before_proposal': [],
        'limit': 1,
        'exclude_type': [],
        'include_status':[],
    }
  )
  print(res)
asyncio.run(async_test())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants