파이썬 3.4.2를 사용하여 로그 파일을 ftp 서버에 업로드합니다 (간단히하기 위해 try와 with 문을 제거했습니다) :Python3 : ftp file upload throws TypeError : str이 버퍼 API를 지원하지 않습니다
import ftplib
ftp = ftplib.FTP(url)
ftp.login(name, password)
ftp.storlines("STOR " + "mylog.log", open("log/mylog.log"))
ftp.close()
mylog.log 파일에는 "text/plain; charset = us-ascii"인코딩이 있습니다. 내 맥북에 다 잘 작동합니다.
Traceback (most recent call last):
File "./ftptest.py", line 7, in <module>
ftp.storlines("STOR " + "mylog.log", open("log/mylog.log"))
File "/usr/lib/python3.4/ftplib.py", line 537, in storlines
if buf[-1] in B_CRLF: buf = buf[:-1]
TypeError: Type str doesn't support the buffer API
나는 그것이 어떤 인코딩 및/또는 로컬 설정 문제 같아요 : 나는 (SSH를 통해) 라즈베리 파이에 나의 작은 프로그램을 실행하면, 나는 다음과 같은 오류 메시지가 나타납니다. 내가 도대체 뭘 잘못하고있는 겁니까? 가장 좋은 방법은 무엇입니까?
Mac에서 사용하는 Python 버전은 무엇입니까? – smarx
@smarx OSX 및 Raspberry Pi에서 3.4.2를 사용하고 있습니다. – armin
놀랍습니다. 나는이 코드가 OS X에서도 실패 할 것으로 기대했을 것이다. – smarx