Balance() not working
obviliontsk opened this issue · 3 comments
Balance() method not working, always return FormatException.
double twoCaptchaBalance = await solver.Balance();
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);
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);
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.