Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71572

Re: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly

Date 2014-05-14 19:38 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly
References <53735242.2010406@rece.vub.ac.be> <87r43wfhw4.fsf@gmail.com> <5373B0A9.1090508@rece.vub.ac.be>
Newsgroups comp.lang.python
Message-ID <mailman.10017.1400092703.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-05-14 19:06, Antoon Pardon wrote:
> op 14-05-14 18:24, Akira Li schreef:
>> Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes:
>>
>>> This is the code I run (python 3.3)
>>>
>>> host = ...
>>> user = ...
>>> passwd = ...
>>>
>>> from ftplib import FTP
>>>
>>> ftp = FTP(host, user, passwd)
>>> ftp.mkd(b'NewDir')
>>> ftp.rmd(b'NewDir')
>>>
>>> This is the traceback
>>>
>>> Traceback (most recent call last):
>>>   File "ftp-problem", line 9, in <module>
>>>     ftp.mkd(b'NewDir')
>>>   File "/usr/lib/python3.3/ftplib.py", line 612, in mkd
>>>     resp = self.voidcmd('MKD ' + dirname)
>>> TypeError: Can't convert 'bytes' object to str implicitly
>>>
>>> The problem is that I do something like this in a backup program.
>>> I don't know the locales that other people use. So I manipulate
>>> all file and directory names as bytes.
>>>
>>> Am I doing something wrong?
>>
>> The error message shows that ftplib expects a string here, not bytes.
>> You could use `ftp.mkd(some_bytes.decode(ftp.encoding))` as a
>> workaround.
>
> Sure but what I like to know: Can this be considered a failing of
> ftplib. Since python3 generally allows paths to be strings as
> well as bytes can't we expect the same of ftplib?
>
> Especially as I assume that path will be converted to bytes anyway
> in order to send it over the network.
>
 From studying the code, I see that it uses the Latin-1 encoding.

On another note, I find it interesting that the default for the timeout
argument uses the 'magic' value -999 rather than, say, None!

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly MRAB <python@mrabarnett.plus.com> - 2014-05-14 19:38 +0100

csiph-web