Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Panic on request challenge #6

Open
PaulDotSH opened this issue Jul 30, 2022 · 2 comments
Open

Panic on request challenge #6

PaulDotSH opened this issue Jul 30, 2022 · 2 comments

Comments

@PaulDotSH
Copy link

When the code gets to

let url = resp.url().as_str().to_owned();

The thread panics, saying

'no entry found for key "set-cookie"'
@winrid
Copy link

winrid commented Mar 29, 2023

It's due to this line:

let cookie = resp.headers()[SET_COOKIE].to_owned();

@winrid
Copy link

winrid commented Mar 29, 2023

An easy fix is:

            match self.client.get(url).header(USER_AGENT, self.user_agent.as_str()).send() {
                Ok(resp) => {
                    let headers = resp.headers();
                    match headers.contains_key(SET_COOKIE) {
                        true => {
                            let url = resp.url().as_str().to_owned();
                            let cookie = resp.headers()[SET_COOKIE].to_owned();
                            match resp.text() {
                                Ok(text) => {
                                    let path = regex::Regex::new(r#"id="challenge-form" action="([^"]*)""#)
                                        .unwrap()
                                        .captures(&text)
                                        .unwrap()[1]
                                        .into();
                                    return (text, url, cookie, path);
                                }
                                Err(e) => eprintln!("At request_challenge() text(), {:?}", e),
                            }
                        }
                        false => {
                            eprintln!("Did not get SET_COOKIE header, trying again. {}", url);
                            sleep(Duration::from_secs(3));
                            // continue
                        }
                    }
                }
                Err(e) => eprintln!("At, request_challenge() send(), {:?}", e),
            }

but not sure this is a solution, not sure why not getting SET_COOKIE in response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants