# Fail to access loal canister with agent-rs

**URL:** <https://forum.dfinity.org/t/fail-to-access-loal-canister-with-agent-rs/34758>\
**Category:** Developers\
**Created:** [September 4, 2024, 4:11pm UTC](https://forum.dfinity.org/t/fail-to-access-loal-canister-with-agent-rs/34758 "2024-09-04T16:11:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![readygo67](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/readygo67/32/13870_2.png) [@readygo67](https://forum.dfinity.org/u/readygo67)\
**Post date:** [September 4, 2024, 4:11pm UTC](https://forum.dfinity.org/t/fail-to-access-loal-canister-with-agent-rs/34758/1 "2024-09-04T16:11:59Z")

</div>

it is ok to access with dfx

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/d/6/d6f07c8f50efaeaebfd71f685f913ed680fc26ea.png)

but fail to access with agent-rs

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/d/3/d36b6213d5dad1191d6f61a98d95b7f0311f36ec.png)

canister code is below:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/f/d/fd2f00be63fdfe9d4dec096bb4734594b0ce8c0f.png)

struggling in access canister without dfx command line.

---

<div class="post-metadata">

**Author:** ![readygo67](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/readygo67/32/13870_2.png) [@readygo67](https://forum.dfinity.org/u/readygo67)\
**Post date:** [September 5, 2024, 2:03am UTC](https://forum.dfinity.org/t/fail-to-access-loal-canister-with-agent-rs/34758/2 "2024-09-05T02:03:57Z")

</div>

It’s very trick in agent-rs, **empty byte sequence**!= **empty argument list.**  
in this case, the following **non-empty bytes** should be provided to indicate **empty argument list.**

```auto
 let args = candid::Encode!().unwrap();
 println!("args: {:?}", args);

```

the whole code is below

```auto
    #[tokio::test]
    async fn agent_test() {
        let a = Agent::builder().with_url("http://127.0.0.1:4943").with_verify_query_signatures(false).build().unwrap();
        let canister_id = Principal::from_text("bkyz2-fmaaa-aaaaa-qaaaq-cai").unwrap();
        let args = candid::Encode!().unwrap();
        println!("args: {:?}", args);
        let result = a.query(&canister_id, "greet").with_arg(args).call().await;
        match result{
            Ok(response) => {
                // Convert response to a string or other suitable format
                println!("Response: {:?}", response); // Print the response
            },
            Err(e) => {
                eprintln!("Error occurred: {}", e);
            }
        }

    }

```

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/0/8/08c7898942179a966baa4d2b1cdc2f160138d8d8.png)
