0
我试图在2分钟内重新连接FTP服务器一次,以访问新生成的文件。但是我面临属性error.not能够识别问题。任何人都可以提出重新连接到FTP服务器的正确方法。如何解决错误:'NoneType'对象在python中没有属性'sendall'
代码:
def Connect1():
ftp=FTP('ipaddress')
ftp.login(username,password)
files=ftp.dir()
for file_ in natsorted(files):
if file_.endswith('.sec.gz'):
file_c=file_.split('/')
file_d=file_c[3]
print file_d
files=date_b+'\\'+file_d
print files
ftp.retrbinary('RETR files', open('C:\\test\\'+file_d, 'wb').write)
ftp.quit()
time.sleep(120)
Connect1()
结果:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-00293e7b319b> in <module>()
----> 1 Connect()
2
3
4
<ipython-input-19-0bc6dc053f87> in Connect()
49 #output_filename1 = os.path.join(files)
50 #print output_filename1
---> 51 ftp.retrbinary('RETR FAO05/DATA_INTV_NEW/'+files, open('C:\\test\\'+file_d, 'wb').write)
52 ftp.quit()
53 time.sleep(110)
C:\Python27\Lib\ftplib.pyc in retrbinary(self, cmd, callback, blocksize, rest)
411 The response code.
412 """
--> 413 self.voidcmd('TYPE I')
414 conn = self.transfercmd(cmd, rest)
415 while 1:
C:\Python27\Lib\ftplib.pyc in voidcmd(self, cmd)
251 def voidcmd(self, cmd):
252 """Send a command and expect a response beginning with '2'."""
--> 253 self.putcmd(cmd)
254 return self.voidresp()
255
C:\Python27\Lib\ftplib.pyc in putcmd(self, line)
179 def putcmd(self, line):
180 if self.debugging: print '*cmd*', self.sanitize(line)
--> 181 self.putline(line)
182
183 # Internal: return one line from the server, stripping CRLF.
C:\Python27\Lib\ftplib.pyc in putline(self, line)
174 line = line + CRLF
175 if self.debugging > 1: print '*put*', self.sanitize(line)
--> 176 self.sock.sendall(line)
177
178 # Internal: send one command to the server (through putline())
AttributeError: 'NoneType' object has no attribute 'sendall'
*请先*修复你的代码片段的缩进 - 就像你的代码引发一个'SyntaxError '。 – 2014-12-04 12:10:12