这个问题通常出现在AWS Glue作业中,其中包含要序列化的自定义对象。它通常会导致以下错误消息:
Error: Python Job failed with error: ‘NewConnectionError’ object has no attribute ‘_sock’
要解决该问题,我们可以使用Python中的dill模块来序列化自定义对象而不是使用Python默认的pickle模块。下面是一些示例代码:
import dill
class CustomObject: def init(self, name): self.name = name
serialized_object = dill.dumps(CustomObject("MyObject"))
deserialized_object = dill.loads(serialized_object)
print(deserialized_object.name)
通过使用dill而不是pickle序列化自定义对象,可以避免AWS Glue作业中出现PicklingError。