Reputation: 2047
I'm using python 3.4.2 to upload a logfile to an ftp server (I removed the try and with statements for simplicity's sake):
import ftplib
ftp = ftplib.FTP(url)
ftp.login(name, password)
ftp.storlines("STOR " + "mylog.log", open("log/mylog.log"))
ftp.close()
The mylog.log file has a "text/plain; charset=us-ascii" encoding. On my macbook everything works fine. When I execute my little program on a raspberry pi (via ssh), I get the following error message:
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
I guess it's some encoding and/or local settings issue. What am I doing wrong? What is the best practice here?
Upvotes: 1
Views: 297
Reputation: 60143
From my reading of http://bugs.python.org/issue6822, I think for Python 3.x, you'll need open("log/mylog.log", "rb")
.
Upvotes: 1