Coder Social home page Coder Social logo

Comments (14)

BobMc98 avatar BobMc98 commented on May 27, 2024 1

@kamoco My code now looks like this:

       public static async Task InitAsync(CancellationToken token = default)
       {
           if (_crumb != null)
           {
               return;
           }

           await _semaphore.WaitAsync(token).ConfigureAwait(false);
           try
           {
               const string userAgentKey = "User-Agent";
               const string userAgentValue = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";

               var response = await "https://login.yahoo.com"
                   .AllowHttpStatus("404")
                   .WithHeader(userAgentKey, userAgentValue)
                   .GetAsync()
                   .ConfigureAwait(false);

               if (response.Cookies.Count == 0)
               {
                   throw new Exception("Failed to obtain Yahoo auth cookie.");
               }
               else
               {
                   _cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

from yahoofinanceapi.

estebanf93 avatar estebanf93 commented on May 27, 2024

me too, since since Dec. 4 too

from yahoofinanceapi.

kamoco avatar kamoco commented on May 27, 2024

I am hitting the same too.

from yahoofinanceapi.

emoreau99 avatar emoreau99 commented on May 27, 2024

found a workaround that seems to work.

In the InitAsync method of the "internal static class YahooSession" class:

-on the line : var response = await "https://login.yahoo.com"
-replace login with fc
-replace the line "_cookie = response.Cookies[0];"
-with : _cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

from yahoofinanceapi.

kamoco avatar kamoco commented on May 27, 2024

Those changes did not work. The response here still throws 502. May be you have some other changes on machine that helped along with these 2 changes ?

var response = await "https://fc.yahoo.com"
.AllowHttpStatus("404")
.WithHeader(userAgentKey, userAgentValue)
.GetAsync()
.ConfigureAwait(false);

from yahoofinanceapi.

BobMc98 avatar BobMc98 commented on May 27, 2024

The workaround from @emoreau99 worked well for me, with the following clarification:

-replace login with fc

For me, I did the opposite. I had "fc.yahoo.com" on that line, and I replaced it with "login.yahoo.com". Everything worked then. The implication being that "fc.yahoo.com" is no longer responding.

from yahoofinanceapi.

kamoco avatar kamoco commented on May 27, 2024

hmm I tried both and none of them worked.

from yahoofinanceapi.

kamoco avatar kamoco commented on May 27, 2024

This worked for me:

change login to fc
Allow 502
replace the _cookie line - _cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

var response = await "https://fc.yahoo.com"
.AllowHttpStatus("502")
.WithHeader(userAgentKey, userAgentValue)
.GetAsync()
.ConfigureAwait(false);

if (response.Cookies.Count == 0)
{
throw new Exception("Failed to obtain Yahoo auth cookie.");
}
else
{
//_cookie = response.Cookies[0];
_cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

from yahoofinanceapi.

reviloxx avatar reviloxx commented on May 27, 2024

For me the request to "https://fc.yahoo.com" runs into a timeout and if I try "https://login.yahoo.com" I only get a cookie with name "AS". With this cookie the next request (_crumb = await "https://query1.finance.yahoo.com/v1/test/getcrumb") throws an error.

from yahoofinanceapi.

irigopou avatar irigopou commented on May 27, 2024

Same as above. Location in Germany, just in case this matters.
Note I used _cookie = response.Cookies[0] as the above suggested FirstOrDefault fails.
The fetched _cookie has Name is "AS" and Value a very long string.
The exception message is:
"Call failed with status code 500 (Internal Server Error): GET https://query1.finance.yahoo.com/v1/test/getcrumb"

from yahoofinanceapi.

reviloxx avatar reviloxx commented on May 27, 2024

I missed the part with "Allow 502". With this change it works again. Thank you @kamoco !

This is how my method looks now:

public static async Task InitAsync(CancellationToken token = default)
{
    if (_crumb != null)
    {
        return;
    }

    await _semaphore.WaitAsync(token).ConfigureAwait(false);
    try
    {
        const string userAgentKey = "User-Agent";
        const string userAgentValue = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";

        var response = await "https://fc.yahoo.com/"
            .AllowHttpStatus("502")
            .WithHeader(userAgentKey, userAgentValue)
            .GetAsync()
            .ConfigureAwait(false);

        if (!response.Cookies.Any(c => c.Name == "A3"))
        {
            throw new Exception("Failed to obtain Yahoo auth cookie.");
        }
        else
        {
            _cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

            _crumb = await "https://query1.finance.yahoo.com/v1/test/getcrumb"
                .WithCookie(_cookie.Name, _cookie.Value)
                .WithHeader(userAgentKey, userAgentValue)
                .GetAsync(token)
                .ReceiveString();

            if (string.IsNullOrEmpty(_crumb))
            {
                throw new Exception("Failed to retrieve Yahoo crumb.");
            }
        }
    }
    finally
    {
        _semaphore.Release();
    }
}

from yahoofinanceapi.

irigopou avatar irigopou commented on May 27, 2024

Thanks mate! Changing to 502 worked for me too!
I noticed though that the invocation of the following takes long time to complete. About 30 secs. Any idea why this is happening?
I guess is some timeout setting. At least, it is invoked only once and afterwards the feeds are fetched without delay by using the discovered cookie.

var response = await "https://fc.yahoo.com"
.AllowHttpStatus("502")//works after 5.12.23
.WithHeader(userAgentKey, userAgentValue)
.GetAsync()
.ConfigureAwait(false);

from yahoofinanceapi.

hbraasch avatar hbraasch commented on May 27, 2024

Thank all, I had same problem and its now working again.

from yahoofinanceapi.

sergemat avatar sergemat commented on May 27, 2024

Fixed with PRs #62 and #63.

from yahoofinanceapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.