使用 Glue 将文件保存到 S3 时出现 Py4JException 错误

Py4JException error while saving file to S3 with Glue

我正在尝试将默认值文件保存到 S3 存储桶但出现以下错误:

An error occurred while calling o654.__getstate__. Trace:
py4j.Py4JException: Method __getstate__([]) does not exist
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
    at py4j.Gateway.invoke(Gateway.java:274)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)

我准备的代码片段,它似乎是 py4j 相关问题。 感谢您的建议!

    BUCKET = 'my_bucket'
    s3 = boto3.client('s3')
    keyid = 'xxxxx'

    print("Uploading S3 object with SSE-KMS")
    s3.put_object(Bucket=BUCKET,
              Key='encrypt-key',
              Body=b'foobar',
              ServerSideEncryption='aws:kms',
              # Optional: SSEKMSKeyId
              SSEKMSKeyId=keyid)
    print("Saving to S3, Done")

潜在问题是 Key 的语法错误。它应该遵循 subfolder/subfolder/file_to_write.txt.

/ 必须添加到每个子文件夹(又名键)名称,否则 AWS 不会将其视为存储桶中的路径。