'NoneType'对象没有'sendall'PYTHON属性 [英] 'NoneType' object has no attribute 'sendall' PYTHON

查看:4358
本文介绍了'NoneType'对象没有'sendall'PYTHON属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的python脚本:

  import os 
import ftplib
import hashlib
导入glob


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

ftp = ftplib.FTP('localhost','kevin403','S $ ip1234')
ftp.cwd('/ var / www / html / image')
.b $ b为glob.glob中的图像(os.path.join('Desktop / images / test * .png')):
打开(图像,'rb')作为文件:
ftp.storbinary('STOR'+ dd +'.png',file)

ftp.close()
ftp.quit()

有人知道这个错误吗?我试图通过ftp将文件发送到另一个文件夹。



运行脚本时出现错误:

  Traceback(最近一次调用的最后一个):
在< module>文件中的第21行/home/kevin403/wwq.py
ftp.quit()
文件/usr/lib/python2.7/ftplib.py,第591行,退出
resp = self.voidcmd('QUIT')
在voidcmd
self.putcmd(cmd)
文件/usr/lib/python2.7/ftplib.py中,第253行, py,第181行,放在putcmd
self.putline(line)
文件/usr/lib/python2.7/ftplib.py,第176行,putline
self.sock .sendall(line)
AttributeError:'NoneType'对象没有属性'sendall'


解决方案


FTP.quit()
发送QUIT命令到服务器并关闭连接。这是关闭连接的礼貌方式,但如果服务器对QUIT命令返回错误,则可能会引发异常。这意味着调用close()方法,该方法会使FTP实例无用于后续调用(请参阅下文)。

FTP.close()
单方面关闭连接。这不应该应用于已经关闭的连接,例如成功调用quit()之后。在这个调用之后,不应再使用FTP实例(在调用close()或quit()之后,您不能通过发出另一个login()方法重新打开连接。)



$ b

只需擦除 ftp.close(),因为 ftp.quit()意味着要调用 .close()函数关闭两次,然后退出,因为套接字已关闭。



FTPlib文档


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'

解决方案

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

这篇关于'NoneType'对象没有'sendall'PYTHON属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆