Overmiind / Puppeteer-sharp-extra

Plugin framework for PuppeteerSharp
MIT License
181 stars 47 forks source link

SolveCaptchaAsync is throwing an error #55

Open AdamB2023 opened 1 year ago

AdamB2023 commented 1 year ago
var browser = await new PuppeteerExtra().Use(recaptchaPlugin).LaunchAsync(new LaunchOptions()
{
    Headless = false
});

 var page = await browser.NewPageAsync();
 await page.GoToAsync("https://patrickhlauke.github.io/recaptcha/");
 await recaptchaPlugin.SolveCaptchaAsync(page).ConfigureAwait(false);

Error:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=PuppeteerExtraSharp
  StackTrace:
   at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptchaApi.<>c.<PendingForResult>b__5_0(RestResponse`1 response)
   at PuppeteerExtraSharp.Plugins.Recaptcha.RestClient.PollingBuilder`1.<ActivatePollingAsync>d__7.MoveNext()
   at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptchaApi.<PendingForResult>d__5.MoveNext()
   at PuppeteerExtraSharp.Plugins.Recaptcha.Provider.AntiCaptcha.AntiCaptcha.<GetSolution>d__3.MoveNext()
   at PuppeteerExtraSharp.Plugins.Recaptcha.Recaptcha.<GetSolutionAsync>d__5.MoveNext()
   at PuppeteerExtraSharp.Plugins.Recaptcha.Recaptcha.<Solve>d__3.MoveNext()
   at PuppeteerExtraSharp.Plugins.Recaptcha.RecaptchaPlugin.<SolveCaptchaAsync>d__2.MoveNext()
   at Program.<Main>d__0.MoveNext() in C:\Users\_\Documents\Visual Studio 2022\Projects\_\_\Program.cs:line 32

  This exception was originally thrown at this call stack:
    [External Code]
    Program.Main(string[]) in Program.cs
olegfridman commented 1 year ago

The issue is in the TaskResultModel. "cost" is declared as a string but according to Anti Captcha's docs, it's a double. Commenting out all of the unused properties (cost, ip, createTime, endTime, solveCount) fixes the issue.

public class TaskResultModel    {
    public int errorId { get; set; } 
    public string status { get; set; } 
    public Solution solution { get; set; } 
    //public double cost { get; set; } 
    //public string ip { get; set; } 
    //public int createTime { get; set; } 
    //public int endTime { get; set; } 
    //public string solveCount { get; set; } 
}
trevorjdaniel-claimit commented 8 months ago

i believe TaskResultModel should now look like this:

`public class TaskResultModel { public int errorId { get; set; } public string status { get; set; } public Solution solution { get; set; } public string cost { get; set; } public string ip { get; set; } public int createTime { get; set; } public int endTime { get; set; } public int solveCount { get; set; } }

public class Solution { public string gRecaptchaResponse { get; set; } public Cookies cookies { get; set; } }

public class Cookies { public string empty { get; set; } }`