Error Too Many Requests
tosatoandrea opened this issue · comments
Hi,
I use the code in the readme for historical prices and I get always this exception:
Call failed with status code 429 (Too Many Requests): GET https://query1.finance.yahoo.com/v1/test/getcrumb'
It seems strange to me, but I don't understand where I'm going wrong
Thank you
@tosatoandrea now you must pass a "User agent" header in the request for crumb, similarly to how you make a request for cookies
Ok thank you, where exactly I can pass User Agent header?
I use only this code:
`try
{
// You should be able to query data from various markets including US, HK, TW
// The startTime & endTime here defaults to EST timezone
var history = await Yahoo.GetHistoricalAsync("SWDA", new DateTime(2023, 1, 1), new DateTime(2023, 7, 7), Period.Monthly);
foreach (var candle in history)
{
string line = $"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, AdjustedClose: {candle.AdjustedClose}";
textBox1.AppendText(Environment.NewLine + line);
}
riuscito = true;
}
catch (Exception ex)
{
textBox1.AppendText(Environment.NewLine + ex.Message);
}`
Thank you
@tosatoandrea the problem is in the library itself. So you should fork the source and modify method "InitAsync" in "YahooSession" class, The request for crumb should look like this:
_crumb = await "https://query1.finance.yahoo.com/v1/test/getcrumb"
.WithHeader(userAgentKey, userAgentValue)
.WithHeader("Accept", acceptHeader)
.WithCookie(_cookie.Name, _cookie.Value)
.GetAsync(token)
.ReceiveString();
Variables userAgentKey and userAgentValue are already defined in this method. The "Accept" header is not necessary AFAIK
Ok thank you very much
Could someone with the authorization and knowledge update the package to a new version 2.3.0 or something, please?
Thanks!