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


Groups > comp.lang.python > #71568 > unrolled thread

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

Started byAkira Li <4kir4.1i@gmail.com>
First post2014-05-14 20:24 +0400
Last post2014-05-14 20:24 +0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly Akira Li <4kir4.1i@gmail.com> - 2014-05-14 20:24 +0400

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

FromAkira Li <4kir4.1i@gmail.com>
Date2014-05-14 20:24 +0400
SubjectRe: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly
Message-ID<mailman.10013.1400084668.18130.python-list@python.org>
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.


--
akira

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web