karlwancl / YahooFinanceApi

A handy Yahoo! Finance api wrapper, based on .NET Standard 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception: Failure to create client

stagnoman opened this issue · comments

Hi there,

I have always successfully used YahooFinanceApi. Today I am getting the following exception using "GetHistoricalAsync": Exception: Failure to create client. Could you kindly tell me what I can do to resolve the exception?

Many Thks for your help
Regards
error

LUCA

Same problem for me....

I suggest you try: https://github.com/dshe/YahooQuotesApi

My program is in VB.net, can I use a C# Api with?

"I suggest you try: https://github.com/dshe/YahooQuotesApi"

give me this problem:

YahooHistory: failure to reset HttpClient.
in YahooQuotesApi.YahooHistoryRequester.d__9.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\History\YahooHistoryRequester.cs: riga 98
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() in YahooQuotesApi.YahooHistoryRequester.<Reset>d__8.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\History\YahooHistoryRequester.cs: riga 67 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in YahooQuotesApi.YahooHistoryRequester.<Request>d__7.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\History\YahooHistoryRequester.cs: riga 35 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.YahooHistory.d__71.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\History\YahooHistory.cs: riga 65 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.ParallelProducerCache2.<Get>d__4.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\Utilities\ParallelProducerCache.cs: riga 34 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.YahooHistory.d__61.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\History\YahooHistory.cs: riga 36 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.YahooQuotes.<b__12_0>d.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 142
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult()
in System.Threading.Tasks.Parallel.<>c__501.<<ForEachAsync>b__50_0>d.MoveNext() in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in YahooQuotesApi.YahooQuotes.<AddHistoryToSecurities>d__12.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 157 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in YahooQuotesApi.YahooQuotes.<GetSecuritiesAsync>d__10.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 93 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.YahooQuotes.d__9.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 68
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() in YahooQuotesApi.YahooQuotes.<GetAsync>d__7.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 45 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
in YahooQuotesApi.YahooQuotes.d__6.MoveNext() in C:\projects\yahooquotesapi\YahooQuotesApi\YahooQuotes.cs: riga 29
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
in Ts.Core.MarketData.YahooConnector2.<>c__DisplayClass6_0.<b__0>d.MoveNext() in C:\Users\giorg\source\repos\TS\Ts.Core\MarketData\YahooConnector2.cs: riga 34

Hi all,
thks a lot
in case YahooFinanceApi doesn't work anymore, I will switch to yfinance

commented

I had same problem getting history data from Yahoo on both YahooFinanceAPI and YahooQuotesAPI. Did yahoo change something to break the code? Did windows have an update that broke the code?

Both work to get current quotes - just not the history.

I can get yahoo history data using python's pandas_datareader without a problem but I need it from C#,

honestly speaking, I had no time to deeply investigate the problem yet. I believe it is protocol http client request vs yahoo server but I am not sure. (maybe ... HTTP2 vs HTTP1)
For the time being, I solved the problem using yfinance that is widely supported and used in the community. It is easy to wrap into a C# project without any performance loss.

commented

Hi, I looked into the code. The problem is that now cookies are empty in response from yahoo finance and that's why it doesn't pass the check that cookies shouldn't be empty. This is the code where it fails https://github.com/karlwancl/YahooFinanceApi/blob/master/YahooFinanceApi/YahooClientFactory.cs. I removed that check and also modified the code for retrieving a crumb. For me now it works fine. I'd push the branch but seems I don't have access rights on doing this.

Great thks! I modified the dll removing check too, It works perfectly!

good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation.

good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation.

hi,
1\ open your program in visual studio
2\ go in references, remove existing YahooFinanceApi.dll,
2\ unzip attached dll. Then in references: right mouse button, add reference and use YahooFinanceApi.dll unzipped
3\ rebuild solution

good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation.

Hi pls disregard the previous dll attached. It doesn't work.
I am working on it.
I will send you late afternoon
Ciao

good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation.

Pls replace your old YahooFinanceApi.dll with this attached below.
YahooFinanceApi.zip

Ciaoooo

commented

good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation.

Pls replace your old YahooFinanceApi.dll with this attached below. YahooFinanceApi.zip

Ciaoooo

Yes it works again, thank you !!

Is this YahooFinanceApi.dll now ok? Will there be a normal upgrade through NuGet for this - a new version 2.1.3? There is also an a 3.0.0-beta3 but is has lots of changes and isn’t very compatible with 2.1.2. I’ve avoided using this so far since it is so different. Thanks, Don From: stagnoman @.> Sent: Wednesday, May 4, 2022 5:53 AM To: karlwancl/YahooFinanceApi @.> Cc: DonWM @.>; Comment @.> Subject: Re: [karlwancl/YahooFinanceApi] Exception: Failure to create client (Issue #52) good news ! Can someone explain how to remove the check? I'm not familiar with this kind of programation. Pls replace your old YahooFinanceApi.dll with this attached below. YahooFinanceApi.zip https://github.com/karlwancl/YahooFinanceApi/files/8620456/YahooFinanceApi.zip Ciaoooo — Reply to this email directly, view it on GitHub <#52 (comment)> , or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQQC4L2CZPWVLFLPXIM54LVIJXLHANCNFSM5UT2IF3A . You are receiving this because you commented. https://github.com/notifications/beacon/AHQQC4JDI2ERAV42MDS7KBDVIJXLHA5CNFSM5UT2IF3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIKME4DQ.gif Message ID: @.*** @.***> >

Is this YahooFinanceApi.dll now ok? Yes, it works.
Will there be a normal upgrade through NuGet for this - a new version 2.1.3? No, in Nuget there is the old one. You have to replace the old dll with mine attached above manually in VS, build the program then.

There is also an a 3.0.0-beta3 but is has lots of changes and isn’t very compatible with 2.1.2. I’ve avoided using this so far since it is so different. Dll above is still net 2.0

For me it does'nt work after 5-6 querry it responds with 401 error

The 401 error was also happening with old dll. Yahoo has implemented some kind of time out defense against sever overloading and potential ddos attacks by tracking the number / frequency of requests from a specific ip address.
A 401 error code means the user is unauthorised.

To avoid the error, the method must be synchronous. I use a Thread.Sleep pause of 500 ms,/1s between requests.
Avoid any parallelism.

Using synchronous calls and 1 second delay has solved the problem.

commented

@lucastagnitta thanks for your dll but i have a problem. Assembly errors with Flurl

@lucastagnitta thanks for your dll but i have a problem. Assembly errors with Flurl

In the past, I got some troubles as well, I am using the following version, installed manually
Flurl 2.5.2
Flurl.Http 2.1.0

I suggest you try the new version (5.1): https://github.com/dshe/YahooQuotesApi

commented

Hi, I looked into the code. The problem is that now cookies are empty in response from yahoo finance and that's why it doesn't pass the check that cookies shouldn't be empty. This is the code where it fails https://github.com/karlwancl/YahooFinanceApi/blob/master/YahooFinanceApi/YahooClientFactory.cs. I removed that check and also modified the code for retrieving a crumb. For me now it works fine. I'd push the branch but seems I don't have access rights on doing this.

Could you please show your exact changes in "YahooClientFactory.cs"? Would be very helpful. Thank you!

YahooFinanceApi.zip
This are my changes that I made to the code in master branch. Just replace files in original solution with files from archive and than rebuild.

commented

YahooFinanceApi.zip This are my changes that I made to the code in master branch. Just replace files in original solution with files from archive and than rebuild.

Thanks for the Code. Now i experience errors after the change and after several requests:

"Call failed with status code 401 (Unauthorized)"

Do you experienced the same problem?

YahooFinanceApi.zip This are my changes that I made to the code in master branch. Just replace files in original solution with files from archive and than rebuild.

Thanks for the Code. Now i experience errors after the change and after several requests:

"Call failed with status code 401 (Unauthorized)"

Do you experienced the same problem?

yes, the 401 error was also happening with old dll. Yahoo has implemented some kind of time out defense against sever overloading and potential ddos attacks by tracking the number / frequency of requests from a specific ip address.
A 401 error code means the user is unauthorised.

To avoid the error, the method must be synchronous. I use a Thread.Sleep pause of 500 ms,/1s between requests.
Avoid any parallelism.