gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 17:26:10 35 4
gpt4 key购买 nike

我当前的 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()

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

运行脚本时出现的错误:

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).

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

FTPlib Documentation

关于python - 'NoneType' 对象没有属性 'sendall' PYTHON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38867346/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com