From 7ac6b026ec8d1d234790ea5fb99e5ee9344e26ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Sat, 23 Mar 2024 18:00:36 +0800 Subject: [PATCH] fix(feature): fix python feature --- src/bin/main.rs | 4 ++-- src/models/client.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 62d1fdd..0afcc55 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -42,7 +42,7 @@ async fn main() { if !is_server { loop { let now = Instant::now(); - get("127.0.0.1:813/path", true).await.unwrap(); + get("127.0.0.1:7076/path", true).await.unwrap(); println!("执行时间: {}", now.elapsed().as_millis()); } } else { @@ -53,7 +53,7 @@ async fn main() { path_route!(&mut router, "/welcome" => welcome); path_route!(&mut router, "/json" => json); - let mut server = Server::new("127.0.0.1", 813, router); + let mut server = Server::new("0.0.0.0", 7076, router); server.run().await; } } diff --git a/src/models/client.rs b/src/models/client.rs index b131176..3884536 100644 --- a/src/models/client.rs +++ b/src/models/client.rs @@ -1,7 +1,9 @@ //! # Oblivion Client use crate::models::packet::{OED, OKE, OSC}; -use crate::exceptions::{OblivionException, PyOblivionException}; +use crate::exceptions::OblivionException; +#[cfg(feature = "python")] +use crate::exceptions::PyOblivionException; use crate::utils::gear::Socket; use crate::utils::generator::generate_key_pair; @@ -20,13 +22,13 @@ use serde_json::{json, Value}; #[cfg_attr(feature = "python", pyclass)] pub struct Response { - #[pyo3(get)] + #[cfg_attr(feature = "python", pyo3(get))] pub header: String, - #[pyo3(get)] + #[cfg_attr(feature = "python", pyo3(get))] pub content: Vec, - #[pyo3(get)] + #[cfg_attr(feature = "python", pyo3(get))] pub olps: String, - #[pyo3(get)] + #[cfg_attr(feature = "python", pyo3(get))] pub status_code: i32, } @@ -62,7 +64,10 @@ impl Response { } pub fn json(&mut self) -> Result { - Ok(from_str::(&self.text()?).unwrap()) + match from_str::(&self.text()?) { + Ok(json) => Ok(json), + Err(_) => Err(OblivionException::BadBytes), + } } }