大佬们好,目前在尝试写一个api的客户端接口,调试了1天,出现此错误:
Jun 21 20:46:28.822 TRACE hyper::client::pool: checkout waiting for idle connection: ("https", api.hbdm.vn)
Jun 21 20:46:28.823 DEBUG reqwest::connect: starting new connection: https://api.hbdm.vn/
Jun 21 20:46:28.823 TRACE hyper::client::connect::http: Http::connect; scheme=Some("https"), host=Some("api.hbdm.vn"), port=None
Jun 21 20:46:28.823 DEBUG hyper::client::connect::dns: resolving host="api.hbdm.vn"
Jun 21 20:46:28.831 DEBUG hyper::client::connect::http: connecting to 13.224.166.33:443
Jun 21 20:46:28.897 TRACE mio::poll: registering with poller
Jun 21 20:46:28.897 TRACE mio::sys::unix::kqueue: registering; token=Token(0); interests=Readable | Writable | Error | Hup
Jun 21 20:46:30.008 DEBUG hyper::client::connect::http: connected to 13.224.166.33:443
Jun 21 20:46:30.793 TRACE hyper::client::conn: client handshake HTTP/1
Jun 21 20:46:30.793 TRACE hyper::client: handshake complete, spawning background dispatcher task
Jun 21 20:46:30.794 TRACE want: signal: Want
Jun 21 20:46:30.794 TRACE want: signal found waiting giver, notifying
Jun 21 20:46:30.794 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: Init, keep_alive: Busy }
Jun 21 20:46:30.794 TRACE want: poll_want: taker wants!
Jun 21 20:46:30.794 TRACE hyper::client::pool: checkout dropped for ("https", api.hbdm.vn)
Jun 21 20:46:30.794 TRACE hyper::proto::h1::role: Client::encode method=GET, body=None
Jun 21 20:46:30.794 TRACE hyper::proto::h1::io: detected no usage of vectored write, flattening
Jun 21 20:46:30.794 DEBUG hyper::proto::h1::io: flushed 152 bytes
Jun 21 20:46:30.794 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: KeepAlive, keep_alive: Busy }
Jun 21 20:46:31.054 TRACE hyper::proto::h1::conn: Conn::read_head
Jun 21 20:46:31.055 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: KeepAlive, keep_alive: Busy }
Jun 21 20:46:31.157 TRACE hyper::proto::h1::conn: Conn::read_head
Jun 21 20:46:31.157 DEBUG hyper::proto::h1::io: read 8192 bytes
Jun 21 20:46:31.157 TRACE hyper::proto::h1::role: Response.parse([Header; 100], [u8; 8192])
Jun 21 20:46:31.157 TRACE hyper::proto::h1::role: Response.parse Complete(617)
Jun 21 20:46:31.157 DEBUG hyper::proto::h1::io: parsed 18 headers
Jun 21 20:46:31.157 DEBUG hyper::proto::h1::conn: incoming body is content-length (7868 bytes)
Jun 21 20:46:31.157 TRACE hyper::proto::h1::decode: decode; state=Length(7868)
Jun 21 20:46:31.158 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Body(Length(293)), writing: KeepAlive, keep_alive: Busy }
Jun 21 20:46:31.158 DEBUG reqwest::async_impl::client: response '200 OK' for https://api.hbdm.vn/api/v1/contract_contract_info
Jun 21 20:46:31.158 TRACE hyper::proto::h1::decode: decode; state=Length(293)
Jun 21 20:46:31.158 DEBUG hyper::proto::h1::io: read 293 bytes
Jun 21 20:46:31.158 DEBUG hyper::proto::h1::conn: incoming body completed
Jun 21 20:46:31.158 TRACE hyper::proto::h1::conn: maybe_notify; read_from_io blocked
Jun 21 20:46:31.158 TRACE want: signal: Want
Jun 21 20:46:31.158 TRACE want: signal found waiting giver, notifying
Jun 21 20:46:31.158 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: Init, keep_alive: Idle }
Jun 21 20:46:31.158 TRACE want: signal: Want
Jun 21 20:46:31.158 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: Init, keep_alive: Idle }
Jun 21 20:46:31.158 TRACE want: poll_want: taker wants!
Jun 21 20:46:31.158 TRACE hyper::client::pool: put; add idle connection for ("https", api.hbdm.vn)
Jun 21 20:46:31.158 DEBUG hyper::client::pool: pooling idle connection for ("https", api.hbdm.vn)
Jun 21 20:46:31.159 TRACE want: signal: Want
Jun 21 20:46:31.159 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Init, writing: Init, keep_alive: Idle }
Error: error decoding response body: data did not match any variant of untagged enum HuobiResponse
Jun 21 20:46:31.159 TRACE hyper::proto::h1::dispatch: client tx closed
Jun 21 20:46:31.160 TRACE hyper::proto::h1::conn: State::close_read()
Jun 21 20:46:31.160 TRACE hyper::proto::h1::conn: State::close_write()
Jun 21 20:46:31.160 TRACE hyper::proto::h1::conn: flushed({role=client}): State { reading: Closed, writing: Closed, keep_alive: Disabled }
Jun 21 20:46:31.160 TRACE hyper::proto::h1::conn: shut down IO complete
Jun 21 20:46:31.160 TRACE mio::poll: deregistering handle with poller
Jun 21 20:46:31.160 TRACE want: signal: Closed
上面接口是get请求,本地可以直接访问;一直提示Error: error decoding response body: data did not match any variant of untagged enum HuobiResponse。
这部分代码如下:
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct HuobiErrorData {
pub code: i64,
pub msg: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(untagged)]
pub enum HuobiResponse<T> {
Success(T),
Error(HuobiErrorData),
}
impl<T: for<'a> Deserialize<'a>> HuobiResponse<T> {
pub fn into_result(self) -> Result<T, Error> {
match self {
Self::Success(t) => Result::Ok(t),
Self::Error(HuobiErrorData { code, msg }) => {
Result::Err(Error::HuobiError { code, msg })
}
}
}
}
不知道如何调试及错误的原因,希望大佬们给予指点。谢谢
1
共 2 条评论, 1 页
评论区
写评论Enum枚举:https://github.com/foonsun/binance-async-rs/blob/master/src/error.rs#L27
JSON处理:https://github.com/foonsun/binance-async-rs/blob/master/src/transport.rs#L209
目前在使用这个Enum枚举来做类似的huobi的处理,一直报不匹配。发现https://api.hbdm.vn/api/v1/contract_contract_info的返回结果的信息可以在Enum的Error的response里匹配到。 我的理解是应该是匹配到T才对,为何会匹配到Error呢?
👇
Mike Tang: 你的 Response 为什么是一个 Enum?不是一般是一个 Struct 么? 然后 untagged 作用是?
你的 Response 为什么是一个 Enum?不是一般是一个 Struct 么? 然后 untagged 作用是?