gpt4 book ai didi

python - 引发ValueError('Fileobj必须实现读取')

转载 作者:行者123 更新时间:2023-12-03 18:40:51 25 4
gpt4 key购买 nike

我正在获取文件大小并将其上传到S3:

def transfer_file_from_ftp_to_s3(bucket_name, ftp_file_path, s3_file_path, ftp_username, ftp_password, chunk_size):
ftp_connection = open_ftp_connection(FTP_HOST, int(FTP_PORT), ftp_username, ftp_password)
ftp_file = ftp_connection.file(ftp_file_path, 'r')
s3_connection = boto3.client('s3')
ftp_file_size = ftp_file._get_size()

if ftp_file_size <= int(chunk_size):
#upload file in one go
print('Transferring complete File from FTP to S3...')
ftp_file_data = ftp_file.read()
s3_connection.upload_fileobj(ftp_file_data, bucket_name, s3_file_path)
print('Successfully Transferred file from FTP to S3!')
ftp_file.close()


我在下面收到此错误消息:

Transferring complete File from FTP to S3...
Traceback (most recent call last):

File "/Users/admin/anaconda2/lib/python2.7/site-packages/boto3/s3/inject.py", line 520, in upload_fileobj
raise ValueError('Fileobj must implement read')

ValueError: Fileobj must implement read


你能给我一些指导吗?谢谢。

最佳答案

您正在上传从文件对象读取的数据,但是方法名称建议您应该传递文件对象本身:

s3_connection.upload_fileobj(ftp_file, bucket_name, s3_file_path)

关于python - 引发ValueError('Fileobj必须实现读取'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57451656/

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