Skip to content

Commit

Permalink
Fixed issue with HTTP status code 502 when creating Yahoo session.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergemat committed Dec 10, 2023
1 parent cc30b5f commit ca95578
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion YahooFinanceApi/YahooSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using System;
using System.Threading;
using System.Linq;

namespace YahooFinanceApi
{
Expand Down Expand Up @@ -62,11 +63,14 @@ public static async Task InitAsync(CancellationToken token = default)

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

if (response.Cookies.Count == 0)
_cookie = response.Cookies.FirstOrDefault(c => c.Name == "A3");

if (_cookie == null)
{
throw new Exception("Failed to obtain Yahoo auth cookie.");
}
Expand Down

0 comments on commit ca95578

Please sign in to comment.