Skip to content

read_state_raw TypeError: certificate field decoded as str instead of bytes #122

Description

@HavenCTO

read_state_raw assumes decoded_obj["certificate"] is CBOR-encoded bytes, but some gateways return it as a hex str. This causes cbor2.loads(str) to fail with TypeError: string indices must be integers, not 'str'.

def read_state_raw(self, canister_id, paths):

and
async def read_state_raw_async(self, canister_id, paths):

Fix: Normalize the certificate value before the inner cbor2.loads:

cert_raw = decoded_obj["certificate"]
if isinstance(cert_raw, str):
    cert_raw = bytes.fromhex(cert_raw)
cert_dict = cbor2.loads(cert_raw)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions