Error connecting to daml hub with python dazl client

Running this script to test things out, ledger party and JWT token are from hub

import asyncio
import dazl

async def main():
    async with dazl.connect(
        oauth_token="<token>",
        url="https://c3botnnnzwyalbec.daml.app",
    ) as client:
        contract = {"admin": "<ledger-party>"}
        await client.create("UserAdmin:Admin", contract)

asyncio.run(main())

The error is

root@2ea78427c1d1:/app# python daml.py
Traceback (most recent call last):
  File "daml.py", line 14, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "daml.py", line 11, in main
    await client.create("UserAdmin:Admin", contract)
  File "/usr/local/lib/python3.7/site-packages/dazl/ledger/grpc/conn_aio.py", line 221, in create
    request = self._submit_and_wait_request(commands, meta)
  File "/usr/local/lib/python3.7/site-packages/dazl/ledger/grpc/conn_aio.py", line 516, in _submit_and_wait_request
    act_as_party = act_as[0]
IndexError: tuple index out of range

The daml template inside UserAdmin.daml is

template Admin
  with
    admin : Party
  where
    signatory admin

    nonconsuming choice OnBoardBank : ContractId Bank
      with
        bank: Party
        name: Text
      controller admin
      do
        create Bank with ..

    nonconsuming choice CreateLoanRequestByKey : ContractId LoanRequest
      with
        id: Text
        farmer: Party
        public: Party
      controller admin
      do
        exerciseByKey @ApprovedCreditRequest (admin, farmer, id) CreateLoanRequest with ..

Is act_as supposed to come from hub? because when supplying oauth_token it doesn’t allow setting act_as or read_as?

On Daml Hub, you don’t actually need to (nor should you) supply a token when running a Python bot as the token is injected for you.

In terms of the ledger party, you can also use the DAML_LEDGER_PARTY environment variable to access the party literal that you configured when you deployed the bot. In looking through our docs, I see we fail to mention this anywhere; we’ll definitely fix the docs as well!

Ah sorry I failed to mention I’m not running this as a bot. I’m trying to access my ledger on hub from a whole separate app/service running django. The workflow is basically

  1. send data from django to daml to onboard various entities (a party + associated data)
  2. daml handles it from here on, running a marketplace
  3. django app should be able to read from ledger, ideally through a stream

Ah I see—this is dazl code running outside of Daml Hub.

Yup in that case you’ll definitely need to pass in a token. Are you passing in a token that corresponds to a party from the identities tab? Additionally the word “Bearer” should not be in your token string: it should simply be the raw token.

1 Like

Yep copy pasted the token you get from the Identities>parties>Copy>JWT dropdown

dazl 7.7.0 contained a regression when dealing with these kinds of tokens, which has been addressed with dazl 7.7.3. Sorry about that!