In the FTP.getresp() method, the KHP FTP server returns a bytes message, where it looks like the FTP library was expecting a string?
Traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/whitesi/khp/ImplicitlyTLS.py", line 42, in connect
self.welcome = self.getresp()
File "/Users/whitesi/anaconda/envs/khp-data/lib/python3.6/ftplib.py", line 236, in getresp
resp = self.getmultiline()
File "/Users/whitesi/anaconda/envs/khp-data/lib/python3.6/ftplib.py", line 222, in getmultiline
line = self.getline()
File "/Users/whitesi/anaconda/envs/khp-data/lib/python3.6/ftplib.py", line 213, in getline
elif line[-1:] in CRLF:
TypeError: 'in <string>' requires string as left operand, not bytes
Potential Fix
Adding this line in the library solved the problem. However, that will be really annoying in prod cause it's a standard library.
def getline(self):
line = self.file.readline(self.maxline + 1)
#Ian: added this check
if type(line) == bytes:
line = line.decode('ascii')
if len(line) > self.maxline:
raise Error("got more than %d bytes" % self.maxline)
if self.debugging > 1:
print('*get*', self.sanitize(line))
if not line:
raise EOFError
if line[-2:] == CRLF:
line = line[:-2]
elif line[-1:] in CRLF:
line = line[:-1]
return line
Bytes versus strings strikes again...
In the
FTP.getresp()
method, the KHP FTP server returns a bytes message, where it looks like the FTP library was expecting a string?Traceback:
Potential Fix Adding this line in the library solved the problem. However, that will be really annoying in prod cause it's a standard library.