2captcha / 2captcha-csharp

C# library for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.
http://2captcha.com
MIT License
84 stars 26 forks source link

Balance() not working #9

Closed obviliontsk closed 1 year ago

obviliontsk commented 2 years ago

Balance() method not working, always return FormatException.

double twoCaptchaBalance = await solver.Balance();

kratzky commented 1 year ago

Could you please provide an example of code that throws this error?

I can't reproduce the issue using sample code:

using CaptchaSvc = TwoCaptcha.TwoCaptcha;
using System;
using System.IO;

CaptchaSvc _processor = new CaptchaSvc(Environment.GetEnvironmentVariable("APIKEY"));

double balance = await _processor.Balance();
Console.WriteLine(balance);
obviliontsk commented 1 year ago

Could you please provide an example of code that throws this error?

I can't reproduce the issue using sample code:

using CaptchaSvc = TwoCaptcha.TwoCaptcha;
using System;
using System.IO;

CaptchaSvc _processor = new CaptchaSvc(Environment.GetEnvironmentVariable("APIKEY"));

double balance = await _processor.Balance();
Console.WriteLine(balance);

I fixed it only with double.Parse(responseString, NumberStyles.Any, CultureInfo.InvariantCulture). I think it's culture/number style problem. TwoCaptcha lib uses Convert.ToDouble() which calls double.Parse(value).

                var client = new HttpClient();
                var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, "http://2captcha.com/res.php?" + $"key={solver.ApiKey}&action=getbalance"), token);
                var body = await response.Content.ReadAsStringAsync(token);
                Settings.Instance.TwoCaptchaBalance = double.Parse(body, NumberStyles.Any, CultureInfo.InvariantCulture);
kratzky commented 1 year ago

I fixed it only with double.Parse(responseString, NumberStyles.Any, CultureInfo.InvariantCulture). I think it's culture/number style problem.

Thanks a lot! I never had an idea how to reproduce this because never used a system with comma as a decimal separator.