line-bot-sdk-rust
line-bot-sdk-rust copied to clipboard
Failed to get_profile and then push_message
First off, thanks for developing this library. When using it I encountered this problem:
I have some code that looks like this. All info are valid.
The bot.push_message call will fail with 400.
If I remove the bot.get_profile call then the bot.push_message call will work correctly.
let line_id = "UXXXXXXXXXXXXXXXXXXXXX";
let bot = LineBot::new(channel_secret.as_str(), access_token.as_str());
let mut messages: Vec<SendMessageType> = Vec::new();
let res = bot.get_profile(line_id);
let _profile = res.unwrap();
messages.push(SendMessageType::TextMessage(TextMessage {
text: String::from("Pushed"),
emojis: None,
}));
let result = bot.push_message(line_id, messages);
I'm new to rust so I haven't found out why this happens yet.
thanks @axblueblader please show me the error message when it fails.
Hi @nanato12 , here is the response log
I set log level to TRACE but that's all I got, sorry, couldn't find other useful error message.
It just works properly when remove bot.get_profile call
Ok(Response { url: Url { scheme: "https", username: "", password: None, host: Some(Domain("api.line.me")), port: None, path: "/v2/bot/message/push", query: None, fragment: None
}, status: 400, headers: {
"server": "AkamaiGHost",
"mime-version": "1.0",
"content-type": "text/html",
"content-length": "216",
"expires": "Thu, 15 Apr 2021 06:36:28 GMT",
"date": "Thu, 15 Apr 2021 06:36:28 GMT",
"connection": "close"
}
})
add "println" and check the response message. and show me.
let result = bot.push_message(line_id, messages);
println!("{:?}", result.unwrap().text());
UserID length is 33.
if length is not 33 or "Uxxxxxx" (x is hex) , response is Ok("{\"message\":\"The property, \'to\', in the request body is invalid (line: -, column: -)\"}").
if UserID is invalid, response is Ok("{\"message\":\"Failed to send messages\"}")
println!("user id length: {:?}", line_id.len());
let _res = bot.push_message(line_id, messages);
println!("bot.push_message: {:?}", _res.unwrap().text());
Length is 33 Here is response text
Ok("<HTML><HEAD>\n<TITLE>Bad Request</TITLE>\n</HEAD><BODY>\n<H1>Bad Request</H1>\nYour browser sent a request that this server could not understand.<P>\nReference #7.6fb42d17.1618478740.0\n</BODY>\n</HTML>\n")
LINE_CHANNEL_SECRET and LINE_CHANNEL_ACCESS_TOKEN correct?
Yes all info are guaranteed to be correct. Because this will work:
let bot = LineBot::new(channel_secret.as_str(), access_token.as_str());
let mut messages: Vec<SendMessageType> = Vec::new();
messages.push(SendMessageType::TextMessage(TextMessage {
text: String::from("Pushed"),
emojis: None,
}));
let result = bot.push_message(line_id, messages);
But this will fail with that error:
let bot = LineBot::new(channel_secret.as_str(), access_token.as_str());
let mut messages: Vec<SendMessageType> = Vec::new();
let res = bot.get_profile(line_id);
let _profile = res.unwrap();
messages.push(SendMessageType::TextMessage(TextMessage {
text: String::from("Pushed"),
emojis: None,
}));
let result = bot.push_message(line_id, messages);
I think it might a bug in the http client or reqwest http client lib (maybe a thread or socket race condition?). When debugging, if I step slowly through each function in the debugger, the push_message call will be successful. Running normally will always get 400. Hope this info is useful
thanks @axblueblader It works without any trouble in my environment. I don't know the exact cause. Sorry....
ye, it could be the Rust version or something anyways thanks for looking into it