Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Client Constructors #43

Closed
wants to merge 4 commits into from
Closed

Conversation

austinjp17
Copy link

Added two new YahooConnector constructors. One using a parameter passed client, giving the user complete discretion over the client build. The second a shortcut to create a proxy-tunneled client.

After a week or so testing I ran into persistent 429 responses, setting the user agent fixed this for me. I assume the proxy would as well but didn't try it.

@austinjp17
Copy link
Author

austinjp17 commented Jun 1, 2024

It would be great as well if reqwest was updated to the latest version. I caught it right after submitting the pr.

@andber1
Copy link

andber1 commented Jun 2, 2024

I have the same issue as you described in #42. The solution with setting the user agent also works for me (maybe a short help with this info should be added to new_w_client?). Thanks!
However, your solution does not compile with feature "blocking" enabled:

error[E0308]: mismatched types
265 |             client,
    |             ^^^^^^ expected `reqwest::blocking::Client`, found `reqwest::Client`

Furthermore, should reqwest be re-exported so that one does not have to fiddle with the correct version?

@xemwebe
Copy link
Owner

xemwebe commented Jun 2, 2024

The tests seem to suffer from the same problem, we would need another solution here too.

@wlk0
Copy link

wlk0 commented Jun 2, 2024

You just need to specify a user agent to fix the 429 response issue:

    pub fn new() -> YahooConnector {        
        YahooConnector {
            client: Client::builder().user_agent( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36").build().unwrap(),
            url: YCHART_URL,
            search_url: YSEARCH_URL,
        }
    }

/// ```
pub fn new_w_proxy(url: &str, auth: Option<(&str, &str)>) -> Result<Self, YahooError> {
let client = if auth.is_some() {
let auth = auth.expect("Conditioned");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, use something like .map_err(...)? instead. It is no good practice to let a library panic.

let proxy = reqwest::Proxy::all(url)?
.basic_auth(auth.0, auth.1);

reqwest::Client::builder()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Client::builder() instead of reqwest::Client::builder(). Client is already imported and direct reference here uses only the non-blocking Client implementation.

.proxy(proxy)
.build()?
} else {
reqwest::Client::builder()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


}

pub fn new_w_client(client: Client) -> Self {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment here.

@xemwebe
Copy link
Owner

xemwebe commented Jun 2, 2024

Thank your for your pull request. I have added some comments

@xemwebe
Copy link
Owner

xemwebe commented Jun 2, 2024

You just need to specify a user agent to fix the 429 response issue:

    pub fn new() -> YahooConnector {        
        YahooConnector {
            client: Client::builder().user_agent( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36").build().unwrap(),
            url: YCHART_URL,
            search_url: YSEARCH_URL,
        }
    }

I have adopted your suggestion and it does seem to solve the problem

@nighostchris
Copy link

@xemwebe Will there be a new version published with this fix soon?

@xemwebe
Copy link
Owner

xemwebe commented Jun 17, 2024

@xemwebe Will there be a new version published with this fix soon?

Just did so.

@xemwebe
Copy link
Owner

xemwebe commented Jun 17, 2024

@austinjp17: The 429 response issue seems to solved by specifying a user agent. If you are still interested in this PR (e.g. for adding the additional constructors), please update your PR to solve the open issues, otherwise I would reject this PR.

@austinjp17
Copy link
Author

austinjp17 commented Jun 18, 2024

Using the new constructor with the predefined agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" worked again for a few days then returned to 429s. I am far from a networking professional but imagine it's because every crate user is requesting from under the same agent. I have returned to using a unique app id string as the agent and haven't had any request rejections since. Let me clean it up and I'll update.

@xemwebe
Copy link
Owner

xemwebe commented Jun 20, 2024

Using the new constructor with the predefined agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" worked again for a few days then returned to 429s. I am far from a networking professional but imagine it's because every crate user is requesting from under the same agent. I have returned to using a unique app id string as the agent and haven't had any request rejections since. Let me clean it up and I'll update.

I may be that yahoo takes some measures to identify and block users who try to download an excessive amount of data. Maybe some randomization is required, or using your own custom user agent (which is possible now).

@xemwebe
Copy link
Owner

xemwebe commented Oct 1, 2024

Are you still interested in the PR or could this be closed?

@austinjp17
Copy link
Author

A unique user agent cleaned it all up for me, can be closed. Appreciate your effort on this

@austinjp17 austinjp17 closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants