使用ftp上传带有python的JSON文件的问题

时间:2016-09-05 14:24:04

标签: python ftp

我需要一些帮助,请使用FTP上传JSON文件,我已尝试阅读解决方案,但我还没有弄明白。

我的代码如下:

ftp = FTP('xxx.xxx.x.xx','Uname','Pword')
ftp.cwd("/incoming")
file=open('C:/MyFile.json', 'rb')
ftp.storbinary('STOR MyFile.json','file')

当我运行时,我收到一条错误消息:

line 505, in storbinary
buf = fp.read(blocksize)
AttributeError: 'str' object has no attribute 'read'

1 个答案:

答案 0 :(得分:1)

ftp.storbinary期望一个类似文件的打开对象,而不是字符串。你应该通过file而不是'file'(我认为这更像是一个错字)。