OfflineIMAP / offlineimap

Read/sync your IMAP mailboxes (python2) [LEGACY: move to offlineimap3]
http://www.offlineimap.org
Other
1.78k stars 360 forks source link

sequence item 1: expected string, NoneType found #493

Closed teto closed 7 years ago

teto commented 7 years ago

Hi, I can't use the remotepasseval to retrieve my mails (.netrc works fine). with secretstorage 2.3.1 and keyring 8.4.1

My config has remotepasseval = keyring.get_password("gmail", "password") (which returns u'myPassword' in a python2 interpreter). My config also has pythonfile = ~/.config/offlineimap/get_settings.py which simply contains import keyring

Here is a faulty run

[1] teto@jedha>  ~/.nix-profile/bin/offlineimap -dimap
OfflineIMAP 7.1.1
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
imaplib2 v2.57 (bundled), Python v2.7.13, OpenSSL 1.0.2l  25 May 2017
Debug mode: Forcing to singlethreaded.
Now debugging for imap: IMAP protocol debugging
Now debugging for : Other offlineimap related sync messages
Account sync gmail:
 [imap]: Using authentication mechanisms ['GSSAPI', 'XOAUTH2', 'CRAM-MD5', 'PLAIN', 'LOGIN']
 *** Processing account gmail
 Establishing connection to imap.gmail.com:993 (gmail-remote)
 [imap]: gmail-remote: level 'tls_compat', version 'None'
 [imap]: Attempting XOAUTH2 authentication
 [imap]: Attempting PLAIN authentication
 ERROR: While attempting to sync account 'gmail'
  sequence item 1: expected string, NoneType found
 *** Finished account 'gmail' in 0:11
 ERROR: Exceptions occurred during the run!
 ERROR: While attempting to sync account 'gmail'
  sequence item 1: expected string, NoneType found

Traceback:
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/accounts.py", line 281, in syncrunner
    self.__sync()
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/accounts.py", line 347, in __sync
    remoterepos.getfolders()
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 452, in getfolders
    imapobj = self.imapserver.acquireconnection()
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/imapserver.py", line 558, in acquireconnection
    self.__authn_helper(imapobj)
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/imapserver.py", line 422, in __authn_helper
    if func(imapobj):
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/imapserver.py", line 348, in __authn_plain
    imapobj.authenticate('PLAIN', self.__plainhandler)
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py", line 734, in authenticate
    typ, dat = self._simple_command('AUTHENTICATE', mechanism.upper())
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py", line 1740, in _simple_command
    return self._command_complete(self._command(name, *args), kw)
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py", line 1466, in _command
    literal = literator(data, rqb)
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py", line 2331, in process
    ret = self.mech(self.decode(data))
  File "/nix/store/zpxxbv7vfbddqvyi1y1rxdfaswp17q0c-offlineimap-7.1.1/lib/python2.7/site-packages/offlineimap/imapserver.py", line 218, in __plainhandler
    retval = NULL.join((authz, authc, passwd))

I wonder what's wrong, if I should use the python3 version (but there seems to be errors with python3 too if I trust the tracker)

nicolas33 commented 7 years ago

Py3 won't work.

remotepasseval is not working because you use 'keyring' in the configuration file directly. It's not possible because keyring is never imported. You have to create your own function in a pythonfile starting with import keyring. E.g.:

import keyring

def get_pass(account_name):
    return keyring.get_password(account_name, "password")

Then it's possible call this function from the configuration file: remotepasseval = get_pass("gmail").

nicolas33 commented 7 years ago

Oh, and don't forget to define the pythonfile configuration option. ,-)

teto commented 7 years ago

I've done as you say (I even bumped nixos offlineimap version to 7.1.2) but I still get

~/.nix-profile/bin/offlineimap                                         ~
OfflineIMAP 7.1.2
  Licensed under the GNU GPL v2 or any later version (with an OpenSSL
exception)
imaplib2 v2.57 (bundled), Python v2.7.13, OpenSSL 1.0.2l  25 May 2017
Account sync gmail:
 *** Processing account gmail
 Establishing connection to imap.gmail.com:993 (gmail-remote)
 ERROR: While attempting to sync account 'gmail'
  sequence item 1: expected string, NoneType found
 *** Finished account 'gmail' in 0:00
ERROR: Exceptions occurred during the run!
ERROR: While attempting to sync account 'gmail'
  sequence item 1: expected string, NoneType found

Traceback:
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/accounts.py",
line 281, in syncrunner
    self.__sync()
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/accounts.py",
line 347, in __sync
    remoterepos.getfolders()
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/repository/IMAP.py",
line 452, in getfolders
    imapobj = self.imapserver.acquireconnection()
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/imapserver.py",
line 558, in acquireconnection
    self.__authn_helper(imapobj)
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/imapserver.py",
line 422, in __authn_helper
    if func(imapobj):
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/imapserver.py",
line 348, in __authn_plain
    imapobj.authenticate('PLAIN', self.__plainhandler)
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py",
line 734, in authenticate
    typ, dat = self._simple_command('AUTHENTICATE', mechanism.upper())
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py",
line 1740, in _simple_command
    return self._command_complete(self._command(name, *args), kw)
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py",
line 1466, in _command
    literal = literator(data, rqb)
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/bundled_imaplib2.py",
line 2331, in process
    ret = self.mech(self.decode(data))
  File
"/nix/store/73f8m3pkimjyqm51pky8yvrnfkd3nvp4-offlineimap-7.1.2/lib/python2.7/site-packages/offlineimap/imapserver.py",
line 218, in __plainhandler
    retval = NULL.join((authz, authc, passwd))

file pointed by pythonfile:

import keyring

def get_pass (service, name):
    return keyring.get_password(service, name)

And my offlineimap config:

remotepasseval = get_pass("gmail", "password")

My previous remotepasseval was inspired by: https://wiki.archlinux.org/index.php/OfflineIMAP#python2-keyring

2017-09-07 19:19 GMT+09:00 Nicolas Sebrecht notifications@github.com:

Oh, and don't forget to define the pythonfile configuration option. ,-)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OfflineIMAP/offlineimap/issues/493#issuecomment-327758495, or mute the thread https://github.com/notifications/unsubscribe-auth/AA2FOqK4SphIPUlsnmGEnrWKUQPDQvxGks5sf8NPgaJpZM4PPYpf .

nicolas33 commented 7 years ago

I couldn't reproduce this error. I wonder this could be related to nixos. Though, I have no idea what the issue could be because I don't know nixos enough.

You might debug the pythonfile yourself with statements like this:

import keyring

def get_pass (service, name):
    v = keyring.get_password(service, name)
    print(v)
    print(type(v))
    return v

This might worth opening an bug report to nixos. Perhaps, there's something obvious that a nixos expert will see explaining why this is not working.

teto commented 7 years ago

thanks for trying; much appreciated. with similar print statements, I get ('TEEESSTTT', u'my password') ('type', <type 'unicode'>) Everything is using python2(.7) in the trace, I see a "bundled_imaplib2", what's the reason to bundle it instead of marking it as a dependancy ? is it a fork ?

nicolas33 commented 7 years ago

Since you get the password, it's likely a bug in offlineimap. I'll check this out. That's weird I can't reproduce this bug, though.

About imaplib 2, see this blog post.

nicolas33 commented 7 years ago

Ok, the problem does not lie in the pythonfile or keyring module. Do you have preauthtunnel enabled? Could you share your configuration file, please?

teto commented 7 years ago

I don't have preauthtunnel, I sent you my config by mail in case it helps.

nicolas33 commented 7 years ago

In the gmail remote section you've defined user = USERNAME instead of remoteuser = USERNAME.

teto commented 7 years ago

Good catch ! Thanks a lot for the help and sorry it was such a silly mistake. As it worked with .netrc, I didn't think about the user parameter (but maybe .netrc just look to match the domain). I can't say the error message was super clear though xD

chris001 commented 7 years ago

I agree. It would be better for the error message to say, Error: sync account is missing value for remoteuser, instead of expected string, NoneType found.

nicolas33 commented 7 years ago

We have a patch currently in the next branch about remoteuser and transporttunnel. I'm not sure it fixes this but it might worth a try.

I'll draft a release once the current work on UTF-8 gets in.

teto commented 6 years ago

So I have an error with with 7.1.5 because my keyring is not registered yet ( my config has remoteusereval = get_pass("gmail", "login") ) but I still find the error message confusing if you don't know the internals:

Thread 'Account sync gmail' terminated with exception:
Traceback (most recent call last):
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/threadutil.py", line 160, in run
    Thread.run(self)
  File "/nix/store/7b2z0vfbs9539ga4pxx5gmli47rz5y3n-python-2.7.14/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/accounts.py", line 268, in syncrunner
    self.remoterepos = Repository(self, 'remote')
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/repository/__init__.py", line 84, in __new__
    return repo(name, account)
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/repository/Gmail.py", line 33, in __init__
    IMAPRepository.__init__(self, reposname, account)
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 42, in __init__
    self.imapserver = imapserver.IMAPServer(self)
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/imapserver.py", line 80, in __init__
    None if self.preauth_tunnel else repos.getuser()
  File "/nix/store/vs06ygjr511zn5wqy0xirv0xwnypn4lw-offlineimap-7.1.5/lib/python2.7/site-packages/offlineimap/repository/IMAP.py", line 187, in getuser
    return localeval.eval(user).encode('UTF-8')
AttributeError: 'NoneType' object has no attribute 'encode'
nicolas33 commented 6 years ago

I agree we might have a better error reporting in this area. Feel free to open a feature request if you think it worth.