使用 Python3.8 的泡菜 EOF

Pickle EOF with Python3.8

提问人:JPV 提问时间:4/16/2023 最后编辑:JPV 更新时间:4/17/2023 访问量:96

问:

我最近刚刚将我的 python 版本从 3.6 更改为 3.8,我正在为我的泡菜文件格式而苦苦挣扎。 我的代码正在将一个对象写入泡菜文件“5lc_payload0.pickle”

with open('5lc_payload0.pickle', 'wb') as f: 
    pickle.dump(my_object, f)

然后通过简单的上传操作上传到 S3。

def upload_files(self, items: List[Tuple[StorageUrl, PathLike]]):
    def upload_item(item):
        #(content_type, encoding) = mimetypes.guess_type(item[0].url)
        content_type='application/octet-stream'
        logger.info(f"Uploading single item {item[0]},{item[1]}, {content_type} ")
        self.upload_file(item[0], item[1], content_type)

    with futures.ThreadPoolExecutor(max_workers=5) as executor:
        submitted = [executor.submit(upload_item, item) for item in items]
        for f in futures.as_completed(submitted):
            f.result()

从 s3 '5lc_payload0_s3.pickle' 下载文件并尝试使用

aws s3 cp s3://temp-data/777775555/5lc_payload0.pickle 5lc_payload0_s3.pickle
with open('5lc_payload0_s3.pickle', 'rb') as f: 
    pickle.load(f)

我得到“EOFError:运行输入”

将两个泡菜文件与“cmp”进行比较时enter image description here

到目前为止,我一直在进行许多软件包版本更改,但没有成功。问题是上面的代码适用于 python3.6,但不适用于 python3.8

我正在使用 pandas 1.4、boto3 1.17.28 和 botocore 1.20.112

菜 python-3.8 eof unexpectendoffile

评论

0赞 user3840170 4/16/2023
<meta.stackoverflow.com/questions/285551>
0赞 JPV 4/16/2023
修复了图像错误
0赞 Marijn 4/16/2023
当您不执行上传/下载步骤并且只是在本地转储文件,然后然后在本地加载它时,它是否有效?这两个文件上都说了什么?运行 Python 代码的机器的操作系统是什么?ls -l
0赞 JPV 4/16/2023
在上传之前读取文件时,它确实有效。我正在 centos07 上工作,当我“ls-lth”时文件是 48MB
0赞 Marijn 4/16/2023
如果没有 ?比较两个文件的确切文件大小非常重要。-h

答: 暂无答案