gpt4 book ai didi

java - 使用 AWS transcribe 时出现主机名不能为空错误

转载 作者:行者123 更新时间:2023-11-30 05:20:41 25 4
gpt4 key购买 nike

我目前有代码:

public class ProviderTranscribeController {

private AmazonTranscribe client =
AmazonTranscribeClient.builder().withRegion(Regions.EU_WEST_2).build();
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.EU_WEST_2).build();


public TranscriptionJob transcribeMp3(){
StartTranscriptionJobRequest request = new StartTranscriptionJobRequest();
request.withLanguageCode(LanguageCode.EsUS);
Media media = new Media();

media.setMediaFileUri(s3.getUrl("bucket", "file.mp3").toString());

request.withMedia(media).withMediaSampleRateHertz(8000);
String transcriptionJobName = "myJob";
request.setTranscriptionJobName(transcriptionJobName);
request.withMediaFormat("mp3");

client.startTranscriptionJob(request);

GetTranscriptionJobRequest jobRequest = new GetTranscriptionJobRequest();
jobRequest.setTranscriptionJobName(transcriptionJobName);
TranscriptionJob transcriptionJob;
transcriptionJob = client.getTranscriptionJob(jobRequest).getTranscriptionJob();

return transcriptionJob;
}
}

但我收到错误:

    hostname cannot be null: java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: hostname cannot be null
at com.amazonaws.util.AwsHostNameUtils.parseRegion(AwsHostNameUtils.java:79)
at com.amazonaws.util.AwsHostNameUtils.parseRegionName(AwsHostNameUtils.java:59)
at



com.amazonaws.auth.internal.AWS4SignerRequestParams.resolveRegion(AWS4SignerRequestParams.java:121)
at com.amazonaws.auth.internal.AWS4SignerRequestParams.<init>(AWS4SignerRequestParams.java:103)
at com.amazonaws.auth.AWS4Signer.sign(AWS4Signer.java:225)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1271)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
at com.amazonaws.services.transcribe.AmazonTranscribeClient.doInvoke(AmazonTranscribeClient.java:349)
at com.amazonaws.services.transcribe.AmazonTranscribeClient.invoke(AmazonTranscribeClient.java:325)
at com.amazonaws.services.transcribe.AmazonTranscribeClient.executeStartTranscriptionJob(AmazonTranscribeClient.java:289)
at com.amazonaws.services.transcribe.AmazonTranscribeClient.startTranscriptionJob(AmazonTranscribeClient.java:264)
at transcribe.back.providers.ProviderTranscribeController.transcribeMp3(ProviderTranscribeController.java:32)
at transcribe.back.services.ServiceCollectHttp.convertBase64(ServiceCollectHttp.java:27)
at transcribe.back.ApplicationHandler.handleRequest(ApplicationHandler.java:24)
at transcribe.back.ApplicationHandler.handleRequest(ApplicationHandler.java:14)

我查找了主机名错误,发现有时是由于区域错误造成的,但我很确定它是正确的,因为我的 s3 正在工作。欢迎任何帮助。

最佳答案

问题似乎出在传递给 awsRegion 参数的字符串中。在下面的代码中

如果 awsRegion 是字符串,则应使用破折号作为分隔符,例如“us-west-2”,否则应该使用 Regions 枚举,例如地区。US_WEST_2。

替代解决方案涉及使用 withEndpointConfiguration 而不是 withRegion

示例:

String ecrEndpoint = "s3.%s.amazonaws.com";
final AmazonS3 s3 = = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(String.format(ecrEndpoint, awsRegion), awsRegion))
...

引用:

java.lang.IllegalArgumentException: hostname cannot be null when trying to obtain AWS ECR Authentication Token

关于java - 使用 AWS transcribe 时出现主机名不能为空错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59625169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com