'NoneType' object has no attribute 'se

2019-07-07 08:28发布

My current python script:

import os
import ftplib
import hashlib
import glob


hashing = "123"
m = hashlib.md5()
m.update(hashing)
dd = m.hexdigest()

ftp = ftplib.FTP('localhost','kevin403','S$ip1234')
ftp.cwd('/var/www/html/image')

for image in glob.glob(os.path.join('Desktop/images/test*.png')):
  with open(image, 'rb') as file:
    ftp.storbinary('STOR '+dd+ '.png', file)

ftp.close()
ftp.quit()

Anybody know this error? I trying to send file over to another folder via ftp.

The error i got when running the script:

Traceback (most recent call last):
File "/home/kevin403/wwq.py", line 21, in <module>
  ftp.quit()
File "/usr/lib/python2.7/ftplib.py", line 591, in quit
  resp = self.voidcmd('QUIT')
File "/usr/lib/python2.7/ftplib.py", line 253, in voidcmd
  self.putcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 181, in putcmd
  self.putline(line)
File "/usr/lib/python2.7/ftplib.py", line 176, in putline
  self.sock.sendall(line)
AttributeError: 'NoneType' object has no attribute 'sendall'

1条回答
对你真心纯属浪费
2楼-- · 2019-07-07 09:08

FTP.quit() Send a QUIT command to the server and close the connection. This is the “polite” way to close a connection, but it may raise an exception if the server responds with an error to the QUIT command. This implies a call to the close() method which renders the FTP instance useless for subsequent calls (see below).

FTP.close() Close the connection unilaterally. This should not be applied to an already closed connection such as after a successful call to quit(). After this call the FTP instance should not be used any more (after a call to close() or quit() you cannot reopen the connection by issuing another login() method).

Just erase ftp.close(), since ftp.quit() implies call .close() function you're telling to close two times, and then quit falls because socket was already closed.

FTPlib Documentation

查看更多
登录 后发表回答