rocklabs-io / ic-py

Python Agent Library for the DFINITY Internet Computer
MIT License
127 stars 26 forks source link

Exceptions must derive from BaseException error #20

Closed bodilyty closed 2 years ago

bodilyty commented 2 years ago

I have a friend who is able to run this exact code, but it gives me this error. I'm running from Jupiter Notebooks through Anaconda.

This is the code:

canister_id = '3mttv-dqaaa-aaaah-qcn6q-cai'

from ic.client import Client
from ic.identity import Identity
from ic.agent import Agent
from ic.candid import encode, decode, Types

iden = Identity()
client = Client(url = "https://ic0.app")
agent = Agent(iden, client)
params = []
params = encode(params)
result = agent.query_raw(canister_id, "listings", params)

And this is the error trace. Any help would be appreciated!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-1481165a8320> in <module>
      4 params = []
      5 params = encode(params)
----> 6 result = agent.query_raw(canister_id, "listings", params)

/opt/anaconda3/lib/python3.7/site-packages/ic/agent.py in query_raw(self, canister_id, method_name, arg)
     72         result = self.query_endpoint(canister_id, data)
     73         if result['status'] == 'replied':
---> 74             arg = decode(result['reply']['arg'])
     75             return arg
     76         elif result['status'] == 'rejected':

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decode(data, retTypes)
   1149         outputs.append({
   1150             'type': t.name,
-> 1151             'value': t.decodeValue(b, types[i])
   1152             })
   1153 

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    870             raise "Recursive type uninitialized"
    871         else:
--> 872             return self._type.decodeValue(b, t)
    873 
    874     @property

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    566         rets = []
    567         for _ in range(length):
--> 568             rets.append(self._type.decodeValue(b, vec._type))
    569         return rets
    570 

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    870             raise "Recursive type uninitialized"
    871         else:
--> 872             return self._type.decodeValue(b, t)
    873 
    874     @property

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    746                 wireType.decodeValue(b, wireType)
    747             else:
--> 748                 res.append(self._components[i].decodeValue(b, wireType))
    749         return res
    750 

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    870             raise "Recursive type uninitialized"
    871         else:
--> 872             return self._type.decodeValue(b, t)
    873 
    874     @property

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    685             expectKey = keys[idx]
    686             exceptValue = self._fields[expectKey]
--> 687             x[expectKey] = exceptValue.decodeValue(b, v)
    688             idx += 1
    689         if idx < len(self._fields):

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    870             raise "Recursive type uninitialized"
    871         else:
--> 872             return self._type.decodeValue(b, t)
    873 
    874     @property

/opt/anaconda3/lib/python3.7/site-packages/ic/candid.py in decodeValue(self, b, t)
    610             return [self._type.decodeValue(b, opt._type)]
    611         else:
--> 612             raise "Not an option value"
    613 
    614     @property

TypeError: exceptions must derive from BaseException
Myse1f commented 2 years ago

I can run this code without error, too.

Where did you get ic-py in Anaconda? I think it have been fixed in recent commits. Use main brach of ic-py would success.

bodilyty commented 2 years ago

Ahhhhh yeah I cloned about a week back and just hadn't thought to pull in updates. Works fine now :)

Sorry for the bother, and thanks!

Pepn commented 2 years ago

The error is still in the 0.0.8 release right? Getting the same results with the same code. (installed using pip21.3.4 on python 3.9.6 on W10)

edit: (yes it is, fixed it by downloading & importing the fresh ic files, manually building the repo with pip didn't work)

bodily11 commented 2 years ago

Ah, yeah. I'm not pip installing right now. I clone the repo locally and then run pip install ./ in the directory. That's how I'm working with things right now because I don't think every change in the main branch is pushed as a version for pip installation.