Getting: The certificate authority is invalid or incorrect when querying Walmart Spelling Correction API
complete
J
John Norton
Here is the raw trace output:
Exception thrown: 'System.Exception' in System.Private.CoreLib.dll
WinRT information: The certificate authority is invalid or incorrect
Exception thrown: 'System.Exception' in System.Net.Http.dll
WinRT information: The certificate authority is invalid or incorrect
Exception thrown: 'System.Exception' in System.Private.CoreLib.dll
WinRT information: The certificate authority is invalid or incorrect
Exception thrown: 'System.Exception' in System.Net.Http.dll
WinRT information: The certificate authority is invalid or incorrect
Exception thrown: 'System.Exception' in System.Private.CoreLib.dll
WinRT information: The certificate authority is invalid or incorrect
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Private.CoreLib.dll
'GroceryList.UWP.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Program Files\WindowsApps\Microsoft.NET.CoreFramework.Debug.2.2_2.2.30316.1_x64__8wekyb3d8bbwe\System.Diagnostics.StackTrace.dll'.
Http Request Error: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Exception: The text associated with this error code could not be found.
The certificate authority is invalid or incorrect
at System.Net.Http.HttpHandlerToFilter.SendAsync(HttpRequestMessage request, CancellationToken cancel)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
at GroceryList.Services.SerpApi.QueryCorrect(String phrase)
Here is the method performing the query:
private static async Task<string> QueryCorrect(string phrase)
{
string newQueryString = null;
Debug.WriteLine("Phrase is: " + phrase);
var newSpellingBuilder = new UriBuilder
{
Scheme = "https",
Host = "serapi.com",
Path = "search.json",
Query = $"engine=walmart&query={phrase}&api_key={AppSettings.ApiKey2}"
};
var httpClientSpelling = new HttpClient();
var httpRequestSpelling = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = newSpellingBuilder.Uri
};
try
{
using var responseSpelling = await httpClientSpelling.SendAsync(httpRequestSpelling);
responseSpelling.EnsureSuccessStatusCode();
var result = await responseSpelling.Content.ReadAsStringAsync();
if (result == null) return null;
var obj = JObject.Parse(result);
var q1 = obj["search_information"] as JObject;
Debug.WriteLine($"spelling query returns: " + q1);
newQueryString = q1["Spelling_fix"]?.ToString();
}
catch (HttpRequestException e)
{
Debug.WriteLine("Http Request Error: " + e);
Crashes.TrackError(e);
}
return newQueryString;
}
Any ideas on this?
It works when I paste the URL into the search bar of the browser just fine.
Illia Zub
marked this post as
complete
Illia Zub
marked this post as
under review
Consider using our .NET wrapper instead: github.com/serpapi/google-search-results-dotnet. If that's not the case, here's a corrected code: https://replit.com/@serpapi/scrape-walmart-dotnet.
J
John Norton
Illia Zub: Thank you for catching that! I would use the Nugget but it is not built for mobile platforms like Xamarin.Forms or MAUI. So I have to do things through the URL.
Thanks again!
John
Ali
Hello John,
I hope you are doing well.
Could this be related to your programming environment? Some of our customers also have had problems with SSL in requests library of Python.
J
John Norton
Ali: I'm programming in C# and the Walmart Search and Product APIs URLs work just fine. It is just the Spelling Correction API