Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(python': 0.07; 'failing': 0.07; 'paths': 0.07; 'python3': 0.07; "subject:' ": 0.07; 'string': 0.09; 'bytes.': 0.09; 'converted': 0.09; 'resp': 0.09; 'assume': 0.14; 'anyway': 0.14; 'expects': 0.16; 'ftplib': 0.16; 'skip:` 40': 0.16; 'subject: \n ': 0.16; 'subject:object': 0.16; 'subject:python3': 0.16; 'typeerror:': 0.16; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'bytes': 0.24; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'generally': 0.29; 'network.': 0.30; 'especially': 0.30; 'code': 0.31; 'received:192.168.1.3': 0.31; 'writes:': 0.31; 'allows': 0.31; 'file': 0.32; 'run': 0.32; '(most': 0.33; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'doing': 0.36; 'shows': 0.36; 'to:addr:python- list': 0.38; 'recent': 0.39; 'expect': 0.39; 'use.': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'subject:Can': 0.60; 'user,': 0.69; 'pardon': 0.84; 'received:195.238': 0.84; 'received:195.238.6': 0.84; 'received:belgacom.be': 0.84; 'received:isp.belgacom.be': 0.84 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBALKvc1NQyLfG/2dsb2JhbAANTINVxkcBgTuDGgEBBHgRCyEWDwkDAgECAUUTBgICiEKrVKAEhWMXjWNyFoQqAQOVWIN5gT2VD2s Date: Wed, 14 May 2014 20:06:33 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: python3; ftplib: TypeError: Can't convert 'bytes' object to str implicitly References: <53735242.2010406@rece.vub.ac.be> <87r43wfhw4.fsf@gmail.com> In-Reply-To: <87r43wfhw4.fsf@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400090861 news.xs4all.nl 2920 [2001:888:2000:d::a6]:33565 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71571 op 14-05-14 18:24, Akira Li schreef: > Antoon Pardon 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 >> 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. -- Antoon Pardon.