com.amazonaws.AmazonClientException:无法执行 HTTP 请求:不知道此类主机 (spark-tunes.s3a.ap-south-1.amazonaws.com) [英] com.amazonaws.AmazonClientException: Unable to execute HTTP request: No such host is known (spark-tunes.s3a.ap-south-1.amazonaws.com)

查看:24
本文介绍了com.amazonaws.AmazonClientException:无法执行 HTTP 请求:不知道此类主机 (spark-tunes.s3a.ap-south-1.amazonaws.com)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 pycharm 从本地模式下的 spark 读取存储在 S3 存储桶中的 json 文件.但我收到以下错误消息:

I am trying to read a json file stored in S3 bucket from spark in local mode via pycharm. But I'm getting the below error message:

"py4j.protocol.Py4JJavaError: 调用 o37.json 时发生错误.: com.amazonaws.AmazonClientException: 无法执行 HTTP 请求: 不知道这样的主机 (spark-tunes.s3a.ap-south-1.amazonaws.com)"

"py4j.protocol.Py4JJavaError: An error occurred while calling o37.json. : com.amazonaws.AmazonClientException: Unable to execute HTTP request: No such host is known (spark-tunes.s3a.ap-south-1.amazonaws.com)"

(spark-tunes 是我的 S3 存储桶名称).

(spark-tunes is my S3 bucket name).

下面是我执行的代码.请帮助我知道我是否遗漏了什么.

Below is the code I executed. Please help me to know if I'm missing something.

spark = SparkSession.builder.appName('DF Read').config('spark.master', 'local').getOrCreate()

spark._jsc.hadoopConfiguration().set("fs.s3a.access.key", "access_key")
spark._jsc.hadoopConfiguration().set("fs.s3a.secret.key", "secret_key")

spark._jsc.hadoopConfiguration().set("fs.s3a.endpoint", "s3a.ap-south-1.amazonaws.com")
spark._jsc.hadoopConfiguration().set("com.amazonaws.services.s3a.enableV4", "true")
spark._jsc.hadoopConfiguration().set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem")

df = spark.read.json("s3a://bucket-name/folder_name/*.json")

df.show(5)

推荐答案

尝试将 fs.s3a.path.style.access 设置为 false,而不是为主机添加存储桶名称的前缀,aws s3 客户端将使用路径下的路径端点

try setting fs.s3a.path.style.access to false and instead of prefixing the bucket name to the host, the aws s3 client will use paths under the endpoint

另外:删除 fs.s3a.impl 行.这是在堆栈溢出示例中流传下来的迷信.不需要.真的.

also: drop the fs.s3a.impl line. That is superstition passed down across stack overflow examples. It's not needed. really.

这篇关于com.amazonaws.AmazonClientException:无法执行 HTTP 请求:不知道此类主机 (spark-tunes.s3a.ap-south-1.amazonaws.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆