closeio / sync-engine

GNU Affero General Public License v3.0
26 stars 9 forks source link

Gmail authentication failed when logout on verify_account #14

Closed zkryakgul closed 4 years ago

zkryakgul commented 4 years ago

When i try to authenticate with gmail account its successfully authenticate but when close connection on verify account section in/opt/sync-engine/inbox/auth/gmail.py file it fails with the following error.

Edit: Same issue with IMAP account authentication

Here is the full traceback:

root@sync-engine:/opt/sync-engine# su inbox -c "bin/inbox-auth some.account@gmail.com"
No handlers could be found for logger "flanker.addresslib.parser"
To authorize Nylas, visit this URL and follow the directions:

https://accounts.google.com/o/oauth2/auth?login_hint=some.account%40gmail.com&access_type=offline&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=986659776516-fg79mqbkbktf5ku10c215vdij918ra0a.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fmail.google.com%2F+https%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar
Enter authorization code: 4/2QERNx7Z6K6ytByC8eGZrTRy-pfuH0U52ifryQhef_3fJA5Nho_tQpw
[INFO] Starting new HTTPS connection (1): www.googleapis.com
[DEBUG] "POST /oauth2/v4/token HTTP/1.1" 200 None
[INFO] Starting new HTTPS connection (1): www.googleapis.com
[DEBUG] "GET /oauth2/v2/tokeninfo?access_token=ya29.a0AfH6SMDBwdybnAF2NZ7S2W0vc4_sv-37z0WGHQQuOW0QBt25bUX51lLRIOF98bqzGghzCwARKG1SmE31L4vFka4fVjJo8Iq-sAK3fDNQd95ORbFI2Aa51-qZGezIfkBVjMxoUusD9-BEWFpNCRE_4x5Ys5dEBqfIWzE HTTP/1.1" 200 None
[INFO] Starting new HTTPS connection (1): www.googleapis.com
[DEBUG] "GET /oauth2/v1/userinfo?access_token=ya29.a0AfH6SMDBwdybnAF2NZ7S2W0vc4_sv-37z0WGHQQuOW0QBt25bUX51lLRIOF98bqzGghzCwARKG1SmE31L4vFka4fVjJo8Iq-sAK3fDNQd95ORbFI2Aa51-qZGezIfkBVjMxoUusD9-BEWFpNCRE_4x5Ys5dEBqfIWzE HTTP/1.1" 200 None
[DEBUG] Connected to host imap.gmail.com over SSL/TLS
[INFO] Starting new HTTPS connection (1): www.googleapis.com
[DEBUG] "POST /oauth2/v4/token HTTP/1.1" 200 None
[DEBUG] > FICD1 AUTHENTICATE **REDACTED**
[DEBUG] < + 
[DEBUG]     matched r'\+( (?P<data>.*))?' => (' ', '')
[DEBUG] write literal size 280
[DEBUG] < * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('CAPABILITY', ' IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584', 'IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584')
[DEBUG] untagged_responses[CAPABILITY] 0 += ["IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584"]
[DEBUG] < FICD1 OK some.account@gmail.com authenticated (Success)
[DEBUG]     matched r'(?P<tag>FICD\d+) (?P<type>[A-Z]+) (?P<data>.*)' => ('FICD1', 'OK', 'some.account@gmail.com authenticated (Success)')
[DEBUG] > FICD2 LIST "" "*"
[DEBUG] < * LIST (\HasNoChildren) "/" "Ar&AV8-iv"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren) "/" "Ar&AV8-iv"', '(\\HasNoChildren) "/" "Ar&AV8-iv"')
[DEBUG] untagged_responses[LIST] 0 += ["(\HasNoChildren) "/" "Ar&AV8-iv""]
[DEBUG] < * LIST (\HasNoChildren) "/" "INBOX"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren) "/" "INBOX"', '(\\HasNoChildren) "/" "INBOX"')
[DEBUG] untagged_responses[LIST] 1 += ["(\HasNoChildren) "/" "INBOX""]
[DEBUG] < * LIST (\HasChildren) "/" "Mailspring"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasChildren) "/" "Mailspring"', '(\\HasChildren) "/" "Mailspring"')
[DEBUG] untagged_responses[LIST] 2 += ["(\HasChildren) "/" "Mailspring""]
[DEBUG] < * LIST (\HasNoChildren) "/" "Mailspring/Snoozed"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren) "/" "Mailspring/Snoozed"', '(\\HasNoChildren) "/" "Mailspring/Snoozed"')
[DEBUG] untagged_responses[LIST] 3 += ["(\HasNoChildren) "/" "Mailspring/Snoozed""]
[DEBUG] < * LIST (\HasNoChildren) "/" "Trash"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren) "/" "Trash"', '(\\HasNoChildren) "/" "Trash"')
[DEBUG] untagged_responses[LIST] 4 += ["(\HasNoChildren) "/" "Trash""]
[DEBUG] < * LIST (\HasChildren \Noselect) "/" "[Gmail]"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasChildren \\Noselect) "/" "[Gmail]"', '(\\HasChildren \\Noselect) "/" "[Gmail]"')
[DEBUG] untagged_responses[LIST] 5 += ["(\HasChildren \Noselect) "/" "[Gmail]""]
[DEBUG] < * LIST (\HasNoChildren \Sent) "/" "[Gmail]/G&APY-nderilmi&AV8- Postalar"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren \\Sent) "/" "[Gmail]/G&APY-nderilmi&AV8- Postalar"', '(\\HasNoChildren \\Sent) "/" "[Gmail]/G&APY-nderilmi&AV8- Postalar"')
[DEBUG] untagged_responses[LIST] 6 += ["(\HasNoChildren \Sent) "/" "[Gmail]/G&APY-nderilmi&AV8- Postalar""]
[DEBUG] < * LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren \\Junk) "/" "[Gmail]/Spam"', '(\\HasNoChildren \\Junk) "/" "[Gmail]/Spam"')
[DEBUG] untagged_responses[LIST] 7 += ["(\HasNoChildren \Junk) "/" "[Gmail]/Spam""]
[DEBUG] < * LIST (\Drafts \HasNoChildren) "/" "[Gmail]/Taslaklar"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\Drafts \\HasNoChildren) "/" "[Gmail]/Taslaklar"', '(\\Drafts \\HasNoChildren) "/" "[Gmail]/Taslaklar"')
[DEBUG] untagged_responses[LIST] 8 += ["(\Drafts \HasNoChildren) "/" "[Gmail]/Taslaklar""]
[DEBUG] < * LIST (\All \HasNoChildren) "/" "[Gmail]/T&APw-m Postalar"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\All \\HasNoChildren) "/" "[Gmail]/T&APw-m Postalar"', '(\\All \\HasNoChildren) "/" "[Gmail]/T&APw-m Postalar"')
[DEBUG] untagged_responses[LIST] 9 += ["(\All \HasNoChildren) "/" "[Gmail]/T&APw-m Postalar""]
[DEBUG] < * LIST (\Flagged \HasNoChildren) "/" "[Gmail]/Y&ATE-ld&ATE-zl&ATE-"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\Flagged \\HasNoChildren) "/" "[Gmail]/Y&ATE-ld&ATE-zl&ATE-"', '(\\Flagged \\HasNoChildren) "/" "[Gmail]/Y&ATE-ld&ATE-zl&ATE-"')
[DEBUG] untagged_responses[LIST] 10 += ["(\Flagged \HasNoChildren) "/" "[Gmail]/Y&ATE-ld&ATE-zl&ATE-""]
[DEBUG] < * LIST (\HasNoChildren \Trash) "/" "[Gmail]/&AMcA9g-p kutusu"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren \\Trash) "/" "[Gmail]/&AMcA9g-p kutusu"', '(\\HasNoChildren \\Trash) "/" "[Gmail]/&AMcA9g-p kutusu"')
[DEBUG] untagged_responses[LIST] 11 += ["(\HasNoChildren \Trash) "/" "[Gmail]/&AMcA9g-p kutusu""]
[DEBUG] < * LIST (\HasNoChildren \Important) "/" "[Gmail]/&ANY-nemli"
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('LIST', ' (\\HasNoChildren \\Important) "/" "[Gmail]/&ANY-nemli"', '(\\HasNoChildren \\Important) "/" "[Gmail]/&ANY-nemli"')
[DEBUG] untagged_responses[LIST] 12 += ["(\HasNoChildren \Important) "/" "[Gmail]/&ANY-nemli""]
[DEBUG] < FICD2 OK Success
[DEBUG]     matched r'(?P<tag>FICD\d+) (?P<type>[A-Z]+) (?P<data>.*)' => ('FICD2', 'OK', 'Success')
[DEBUG] untagged_responses[LIST] => ['(\\HasNoChildren) "/" "Ar&AV8-iv"', '(\\HasNoChildren) "/" "INBOX"', '(\\HasChildren) "/" "Mailspring"', '(\\HasNoChildren) "/" "Mailspring/Snoozed"', '(\\HasNoChildren) "/" "Trash"', '(\\HasChildren \\Noselect) "/" "[Gmail]"', '(\\HasNoChildren \\Sent) "/" "[Gmail]/G&APY-nderilmi&AV8- Postalar"', '(\\HasNoChildren \\Junk) "/" "[Gmail]/Spam"', '(\\Drafts \\HasNoChildren) "/" "[Gmail]/Taslaklar"', '(\\All \\HasNoChildren) "/" "[Gmail]/T&APw-m Postalar"', '(\\Flagged \\HasNoChildren) "/" "[Gmail]/Y&ATE-ld&ATE-zl&ATE-"', '(\\HasNoChildren \\Trash) "/" "[Gmail]/&AMcA9g-p kutusu"', '(\\HasNoChildren \\Important) "/" "[Gmail]/&ANY-nemli"']
[DEBUG] > FICD3 LOGOUT
[DEBUG] < * BYE LOGOUT Requested
[DEBUG]     matched r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?' => ('BYE', ' LOGOUT Requested', 'LOGOUT Requested')
[DEBUG] untagged_responses[BYE] 0 += ["LOGOUT Requested"]
[DEBUG] BYE response: LOGOUT Requested
[WARNING] {"latency": 50250, "modname": "__main__", "level": "warning", "timestamp": "2020-07-22T05:37:32.432223Z", "module": "contextlib:35", "funcname": "main", "greenlet_id": 140300415329776, "event": "Long transaction"}

[ERROR] {"error_traceback": "Traceback (most recent call last):\n  File \"bin/inbox-auth\", line 72, in <module>\n    main()\n  File \"/usr/local/lib/python2.7/dist-packages/click/core.py\", line 488, in __call__\n    return self.main(*args, **kwargs)\n  File \"/usr/local/lib/python2.7/dist-packages/click/core.py\", line 474, in main\n    self.invoke(ctx)\n  File \"/usr/local/lib/python2.7/dist-packages/click/core.py\", line 659, in invoke\n    ctx.invoke(self.callback, **ctx.params)\n  File \"/usr/local/lib/python2.7/dist-packages/click/core.py\", line 325, in invoke\n    return callback(*args, **kwargs)\n  File \"bin/inbox-auth\", line 63, in main\n    if auth_handler.verify_account(account):\n  File \"/opt/sync-engine/inbox/auth/gmail.py\", line 199, in verify_account\n    conn.logout()\n  File \"/usr/local/lib/python2.7/dist-packages/imapclient/imapclient.py\", line 379, in logout\n    typ, data = self._imap.logout()\n  File \"/usr/lib/python2.7/imaplib.py\", line 550, in logout\n    self.shutdown()\n  File \"/usr/local/lib/python2.7/dist-packages/imapclient/tls.py\", line 63, in shutdown\n    imaplib.IMAP4.shutdown(self)\n  File \"/usr/lib/python2.7/imaplib.py\", line 265, in shutdown\n    self.sock.shutdown(socket.SHUT_RDWR)\nAttributeError: 'SSLSocket' object has no attribute 'shutdown'\n", "level": "error", "timestamp": "2020-07-22T05:37:32.438803Z", "error_name": "AttributeError", "error_message": "'SSLSocket' object has no attribute 'shutdown'", "module": "nylas.logging.log:234", "greenlet_id": 140300415329776}
jkemp101 commented 4 years ago

Are you using requirements_frozen.txt for the dependencies? That could be the issue if you are using requirements.txt. We just moved stuff to this repo, a bunch of cleanup will be happening shortly which will include removing the old requirements file.

zkryakgul commented 4 years ago

Yep, that was the problem. I replace with correct requirements and its been fixed now. By the way do you guys have any plan for dockerized sync-engine? For now im using a self edited version of this dockerfile for my docker sync-engine: https://github.com/nhurel/nylas-sync-engine. If you have that kind a plan i would be glad with contribute and help for the development.

jkemp101 commented 4 years ago

We actually run this in Docker ourselves but don't have the Dockerfile in this repo. I'll have to take a look at it to see if there is anything specific to our infrastructure. We might be able to move it to this repo at some point. I created https://github.com/closeio/sync-engine/issues/16 to remind us.