fopnp icon indicating copy to clipboard operation
fopnp copied to clipboard

The data returned by the list_folders method is a list of three-tuples.

Open rstewart2702 opened this issue 3 years ago • 6 comments

The data in each three tuple are extracted by the iteration in the program into: flags, a tuple or iterable of bytestrings delimiter, a bytestring folder_name, an encoded string (Unicode, according to the Python3 standard)

This change adds code to invoke the bytestring type's decode method, which is necessary to convert the bytestring data into Unicode data acceptable in the later incarnations of Python.

rstewart2702 avatar Jul 29 '21 17:07 rstewart2702

I suppose Menno must have continued development on imaplib, and introduced an incompatibility. Could you try installing imapclient==0.13.0 and see whether that fixes your problem?

brandon-rhodes avatar Jul 29 '21 21:07 brandon-rhodes

Still get the same error:

>>> data = c.list_folders()
>>> data[0]
((b'\\HasNoChildren',), b'/', 'Caroline_math')
>>> for flags, delimiter, folder_name in data:
...     print('  %-30s%s %s' % (' '.join(flags), delimiter, folder_name))
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: sequence item 0: expected str instance, bytes found
>>> 

And that's with:

pip freeze
IMAPClient==0.13
six==1.16.0

rstewart2702 avatar Jul 29 '21 22:07 rstewart2702

Well, drat. I wonder what could have changed since I ran the examples myself and published them?

I spent about an hour trying to get the Network Playground up and running again and, wow, 14.04 is very old and can't even install Python packages any more. I wonder if I should try modernizing it? It would be on my own time, as the publisher isn't funding further work on the project at this point. I don't have a good feeling for whether getting things running again would be just a couple of hours of work or something more like a full week.

My main goal is not to break this script for anyone for whom it was already working.

What operating system were you running the script under, in case that makes a difference?

brandon-rhodes avatar Jul 29 '21 22:07 brandon-rhodes

I'm running under Windows 10, with Python 3.9.4. PEP 461 was informative, and may help explain, but I didn't read it in detail.

I also pushed a different proposed change to the branch, which is "smaller" or less invasive...

rstewart2702 avatar Jul 29 '21 22:07 rstewart2702

Thanks, that does look less invasive! I'll try to arrange for a test tomorrow or next week.

brandon-rhodes avatar Jul 29 '21 22:07 brandon-rhodes

For what it's worth: I haven't had time to test this hypothesis, but my money's on the changes introduced to the official Python release at 3.5, specifically, changes introduced by "PEP 461 -- Adding % formatting to bytes and bytearray".

rstewart2702 avatar Jul 30 '21 15:07 rstewart2702