yahoo_finance_api icon indicating copy to clipboard operation
yahoo_finance_api copied to clipboard

Custom Client Constructors

Open austinjp17 opened this issue 1 year ago • 11 comments

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 avatar Jun 01 '24 04:06 austinjp17

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

austinjp17 avatar Jun 01 '24 04:06 austinjp17

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?

andber1 avatar Jun 02 '24 15:06 andber1

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

xemwebe avatar Jun 02 '24 18:06 xemwebe

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,
        }
    }

wlk0 avatar Jun 02 '24 18:06 wlk0

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

xemwebe avatar Jun 02 '24 18:06 xemwebe

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

xemwebe avatar Jun 02 '24 19:06 xemwebe

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

nighostchris avatar Jun 16 '24 19:06 nighostchris

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

Just did so.

xemwebe avatar Jun 17 '24 17:06 xemwebe

@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.

xemwebe avatar Jun 17 '24 17:06 xemwebe

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.

austinjp17 avatar Jun 18 '24 15:06 austinjp17

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 avatar Jun 20 '24 06:06 xemwebe

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

xemwebe avatar Oct 01 '24 21:10 xemwebe

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

austinjp17 avatar Oct 02 '24 04:10 austinjp17