提问人:sajid 提问时间:11/17/2023 最后编辑:Helensajid 更新时间:11/17/2023 访问量:78
错误:无法建立 SSL 连接,请参阅内部异常
Error: The SSL connection could not be established, see inner exception
问:
我正在尝试运行以下 C# 代码:
using OpenAI_API;
using OpenAI_API.Completions;
class Program
{
static async Task Main(string[] args)
{
var openAiApiKey = "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"; // Replace with your OpenAI API key
APIAuthentication aPIAuthentication = new APIAuthentication(openAiApiKey);
OpenAIAPI openAiApi = new OpenAIAPI(aPIAuthentication);
try
{
string prompt = "Once upon a time";
string model = "text-davinci-003";
int maxTokens = 50;
var completionRequest = new CompletionRequest
{
Prompt = prompt,
Model = model,
MaxTokens = maxTokens,
};
var completionResult = await openAiApi.Completions.CreateCompletionAsync(completionRequest);
var generatedText = completionResult.Completions[0].Text; //completionResult.Choices[0].Text.Trim();
Console.WriteLine("Generated text:");
Console.WriteLine(generatedText);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Console.WriteLine(ex.InnerException);
}
}
}
但是遇到例外:
Error: The SSL connection could not be established, see inner exception.
System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: PartialChain
at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)
at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
请指导更改以解决。我正在控制台应用程序中尝试上述代码。
无异常地运行代码。
答: 暂无答案
评论