Python 3.6 ftplib STOR错误

时间:2017-10-10 20:05:44

标签: python-3.x ftplib

我对Python(3.6)和ftplib有疑问。 我重新安装了Windows(10),我的一个旧脚本无法运行。有问题的一行是:

  

conn.storlines(' STOR runes.txt',open(' D:\ runes.txt',' r'))

我不断得到的错误是:

Traceback (most recent call last):
  File "C:\Users\ch1zra\Saved Games\Diablo II\linereader.py", line 108, in <module>
    conn.storlines('STOR runes.txt', open('D:\\runes.txt','r'))
  File "C:\Python\lib\ftplib.py", line 536, in storlines
    if buf[-1] in B_CRLF: buf = buf[:-1]
TypeError: a bytes-like object is required, not 'str'

该文件存在。 这之前有用,但是我运行的是旧版本的Python(2.7 IIRC)。

非常感谢帮助,谢谢你。

1 个答案:

答案 0 :(得分:2)

TypeError异常表示需要像object这样的字节。用二进制模式打开文件。

更改

conn.storlines('STOR runes.txt', open('D:\\runes.txt','r'))

要:

conn.storlines('STOR runes.txt', open('D:\\runes.txt','rb'))