简体   繁体   English

'NoneType'对象没有属性'sendall'PYTHON

[英]'NoneType' object has no attribute 'sendall' PYTHON

My current python script: 我目前的python脚本:

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. 我试图通过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'

FTP.quit() Send a QUIT command to the server and close the connection. FTP.quit()向服务器发送QUIT命令并关闭连接。 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. 这是关闭连接的“礼貌”方式,但如果服务器响应QUIT命令的错误,则可能引发异常。 This implies a call to the close() method which renders the FTP instance useless for subsequent calls (see below). 这意味着调用close()方法,该方法使得FTP实例对后续调用无效(见下文)。

FTP.close() Close the connection unilaterally. FTP.close()单方面关闭连接。 This should not be applied to an already closed connection such as after a successful call to quit(). 这不应该应用于已经关闭的连接,例如在成功调用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). 在此调用之后,不应再使用FTP实例(在调用close()或quit()之后,您无法通过发出另一个login()方法重新打开连接)。

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. 只需擦除ftp.close() ,因为ftp.quit()意味着调用.close()函数,你要告诉它关闭两次,然后因为socket已经关闭而退出。

FTPlib Documentation FTPlib文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM