나는 FTP 서버에서 .zip 파일을 다운로드하려고 나는이 오류가 계속 :는 형식 오류를 얻기
File "C:/filename.py", line 37, in handleDownload
file.write(block)
TypeError: descriptor 'write' requires a 'file' object but received a 'str'
여기 (http://postneo.com/stories/2003/01/01/beyondTheBasicPythonFtplibExample.html에서 차용) 내 코드의를 :
def handleDownload(block):
file.write(block)
print ".",
ftp = FTP('ftp.godaddy.com') # connect to host
ftp.login("auctions") # login to the auctions directory
print ftp.retrlines("LIST")
filename = 'auction_end_tomorrow.xml.zip'
file = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, handleDownload)
file.close()
ftp.close()
Python 2.7에서이 코드를 실행하면 파일이 성공적으로 다운로드됩니다. 전체 코드 샘플입니까? 내가 추가 한 것은 import 문이었습니다 :'ftplib import ftp'에서 그것은 올바르게 작동합니다. –
"block"(제공된 코드에 표시되지 않은 값이 있음)이라는 변수는 문자열이 아닌 파일 객체로 간주됩니다 (상당히 명확합니다). 더 많은 코드를 포함하면 더 많은 도움을 드릴 수 있습니다. – alexy13