google / import-mailbox-to-gmail

Import .mbox files into Google Workspace

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access Token / Credentials Issue

ScottAndrews888 opened this issue · comments

Please help with what might seem like a simple issue. I followed the directions very easily, but I am getting an error as you can see where the credentials cannot be accessed. Please advise if I am doing something incorrectly.

C:\Users\Sandrews>C:\Python27\import-mailbox-to-gmail.py --json C:\Users\Sandrews\Downloads\115607657907XXXXXXXXX.json --dir C:\mbox
13:40:20 INFO main@import-mailbox-to-gmail.py *** Starting import-mailbox-to-gmail 1.3 on Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] ***
13:40:20 INFO main@import-mailbox-to-gmail.py Arguments:
13:40:20 INFO main@import-mailbox-to-gmail.py auth_host_name: 'localhost'
13:40:20 INFO main@import-mailbox-to-gmail.py auth_host_port: [8080, 8090]
13:40:20 INFO main@import-mailbox-to-gmail.py dir: 'C:\mbox'
13:40:20 INFO main@import-mailbox-to-gmail.py fix_msgid: True
13:40:20 INFO main@import-mailbox-to-gmail.py httplib2debuglevel: 0
13:40:20 INFO main@import-mailbox-to-gmail.py json: 'C:\Users\Sandrews\Downloads\115607657907XXXXXXXXX.json'
13:40:20 INFO main@import-mailbox-to-gmail.py log: 'import-mailbox-to-gmail-29668.log'
13:40:20 INFO main@import-mailbox-to-gmail.py logging_level: 'INFO'
13:40:20 INFO main@import-mailbox-to-gmail.py noauth_local_webserver: False
13:40:20 INFO main@import-mailbox-to-gmail.py num_retries: 10
13:40:20 INFO main@import-mailbox-to-gmail.py replace_quoted_printable: True
13:40:20 INFO main@import-mailbox-to-gmail.py Processing user XXXX@domain.com
13:40:20 ERROR main@import-mailbox-to-gmail.py Can't get access token for user general@aceexhibits.com
13:40:20 ERROR main@import-mailbox-to-gmail.py Can't process user XXXXX@domain.com
Traceback (most recent call last):
File "C:\Python27\import-mailbox-to-gmail.py", line 303, in main
credentials = get_credentials(username)
File "C:\Python27\import-mailbox-to-gmail.py", line 122, in get_credentials
scopes=SCOPES).create_delegated(username)
File "C:\Python27\lib\site-packages\oauth2client\service_account.py", line 223, in from_json_keyfile_name
revoke_uri=revoke_uri)
File "C:\Python27\lib\site-packages\oauth2client\service_account.py", line 172, in _from_parsed_json_keyfile
'Expected', client.SERVICE_ACCOUNT)
ValueError: ('Unexpected credentials type', None, 'Expected', 'service_account')
13:40:20 INFO main@import-mailbox-to-gmail.py *** Done importing all users from directory 'C:\mbox'
13:40:20 INFO main@import-mailbox-to-gmail.py *** Import summary:
13:40:20 INFO main@import-mailbox-to-gmail.py 0 users imported with no failures
13:40:20 INFO main@import-mailbox-to-gmail.py 0 users imported with some failures
13:40:20 INFO main@import-mailbox-to-gmail.py 1 users failed
13:40:20 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) imported with no failures
13:40:20 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) imported with some failures
13:40:20 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) failed
13:40:20 INFO main@import-mailbox-to-gmail.py 0 messages imported successfully
13:40:20 INFO main@import-mailbox-to-gmail.py 0 messages failed

13:40:20 INFO main@import-mailbox-to-gmail.py *** Check log file import-mailbox-to-gmail-29668.log for detailed errors.
13:40:20 INFO main@import-mailbox-to-gmail.py Finished.

Hi,

This usually happens if you use the wrong JSON file. It should start with "type": "service_account", if it doesn't, then make sure you download the key JSON file from the "Service accounts" section, and not the "OAuth 2.0 client IDs" section.

Thank you for the advice. I tried to create a new service account and downloaded both versions of the json file. Both are having the same errors when processing. Note that the downloaded name of the json file did not have an _ between "Gmail" and "API...". I added the underscore between Gmail and API because the file name was not recognized with a space. Perhaps this is causing a problem? The following is the response I am receiving. Please let me know if you see what else I am doing wrong that needs to be corrected. Thank you for your help.

C:\Users\Sandrews>C:\Python27\import-mailbox-to-gmail.py --json C:\Users\Sandrews\Downloads\Gmail-API-ad776fdXXXXX.json --dir C:\mbox
14:50:16 INFO main@import-mailbox-to-gmail.py *** Starting import-mailbox-to-gmail 1.3 on Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] ***
14:50:16 INFO main@import-mailbox-to-gmail.py Arguments:
14:50:16 INFO main@import-mailbox-to-gmail.py auth_host_name: 'localhost'
14:50:16 INFO main@import-mailbox-to-gmail.py auth_host_port: [8080, 8090]
14:50:16 INFO main@import-mailbox-to-gmail.py dir: 'C:\mbox'
14:50:16 INFO main@import-mailbox-to-gmail.py fix_msgid: True
14:50:16 INFO main@import-mailbox-to-gmail.py httplib2debuglevel: 0
14:50:16 INFO main@import-mailbox-to-gmail.py json: 'C:\Users\Sandrews\Downloads\Gmail-API-ad776fdXXXXX.json'
14:50:16 INFO main@import-mailbox-to-gmail.py log: 'import-mailbox-to-gmail-10764.log'
14:50:16 INFO main@import-mailbox-to-gmail.py logging_level: 'INFO'
14:50:16 INFO main@import-mailbox-to-gmail.py noauth_local_webserver: False
14:50:16 INFO main@import-mailbox-to-gmail.py num_retries: 10
14:50:16 INFO main@import-mailbox-to-gmail.py replace_quoted_printable: True
14:50:16 INFO main@import-mailbox-to-gmail.py Processing user email@domain.com
14:50:16 WARNING autodetect@init.py file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\googleapiclient\discovery_cache_init_.py", line 41, in autodetect
from . import file_cache
File "C:\Python27\lib\site-packages\googleapiclient\discovery_cache\file_cache.py", line 41, in
'file_cache is unavailable when using oauth2client >= 4.0.0')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0
14:50:16 INFO _retrieve_discovery_doc@discovery.py URL being requested: GET https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest
14:50:16 INFO new_request@transport.py Attempting refresh to obtain initial access_token
14:50:17 INFO _do_refresh_request@client.py Refreshing access_token
14:50:18 INFO _do_refresh_request@client.py Failed to retrieve access token: {
"error" : "unauthorized_client",
"error_description" : "Client is unauthorized to retrieve access tokens using this method."
}
14:50:18 ERROR main@import-mailbox-to-gmail.py Can't get access token for user email@domain.com
14:50:18 ERROR main@import-mailbox-to-gmail.py Can't process user email@domain.com
Traceback (most recent call last):
File "C:\Python27\import-mailbox-to-gmail.py", line 307, in main
service = discovery.build('gmail', 'v1', http=http)
File "C:\Python27\lib\site-packages\oauth2client_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Python27\lib\site-packages\googleapiclient\discovery.py", line 228, in build
requested_url, discovery_http, cache_discovery, cache)
File "C:\Python27\lib\site-packages\googleapiclient\discovery.py", line 275, in _retrieve_discovery_doc
resp, content = http.request(actual_url)
File "C:\Python27\lib\site-packages\oauth2client\transport.py", line 159, in new_request
credentials._refresh(orig_request_method)
File "C:\Python27\lib\site-packages\oauth2client\client.py", line 744, in _refresh
self._do_refresh_request(http)
File "C:\Python27\lib\site-packages\oauth2client\client.py", line 812, in _do_refresh_request
raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
HttpAccessTokenRefreshError: unauthorized_client: Client is unauthorized to retrieve access tokens using this method.
14:50:18 INFO main@import-mailbox-to-gmail.py *** Done importing all users from directory 'C:\mbox'
14:50:18 INFO main@import-mailbox-to-gmail.py *** Import summary:
14:50:18 INFO main@import-mailbox-to-gmail.py 0 users imported with no failures
14:50:18 INFO main@import-mailbox-to-gmail.py 0 users imported with some failures
14:50:18 INFO main@import-mailbox-to-gmail.py 1 users failed
14:50:18 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) imported with no failures
14:50:18 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) imported with some failures
14:50:18 INFO main@import-mailbox-to-gmail.py 0 labels (mbox files) failed
14:50:18 INFO main@import-mailbox-to-gmail.py 0 messages imported successfully
14:50:18 INFO main@import-mailbox-to-gmail.py 0 messages failed

14:50:18 INFO main@import-mailbox-to-gmail.py *** Check log file import-mailbox-to-gmail-10764.log for detailed errors.
14:50:18 INFO main@import-mailbox-to-gmail.py Finished.

The good news is that error means that you are using the correct JSON file. :)

The error message unauthorized_client: Client is unauthorized to retrieve access tokens using this method. means that the scopes weren't correctly authorized in the Admin console of the G Suite domain (steps 16+ on https://github.com/google/import-mailbox-to-gmail).

Even if you authorized it correctly, it could take a while (usually less than an hour) for the permissions to apply.

Hi @ScottAndrews888,
I have the same issue. Did you manage to get it work ?

@yaaax, which of the errors are you getting?

@eesheesh I get the same response "Client is unauthorized to retrieve access tokens using this method."

2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:286) *** Starting import-mailbox-to-gmail 1.3 on Python 2.7.13 (default, Dec 17 2016, 23:03:43) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] ***
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:287) Arguments:
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	auth_host_name: 'localhost'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	auth_host_port: [8080, 8090]
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	dir: './'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	fix_msgid: True
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	httplib2debuglevel: 0
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	json: 'Gmail API-2f4282a7c0c4.json'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	log: 'import-mailbox-to-gmail-17518.log'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	logging_level: 'INFO'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	noauth_local_webserver: False
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	num_retries: 10
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:289) 	replace_quoted_printable: True
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:302) Processing user yaacov@goodimpact.studio
2017-03-12T16:36:01 (+0100) 17518 WARNING autodetect (__init__.py:44) file_cache is unavailable when using oauth2client >= 4.0.0
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
    from . import file_cache
  File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
    'file_cache is unavailable when using oauth2client >= 4.0.0')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0
2017-03-12T16:36:01 (+0100) 17518 INFO _retrieve_discovery_doc (discovery.py:273) URL being requested: GET https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest
2017-03-12T16:36:01 (+0100) 17518 INFO new_request (transport.py:157) Attempting refresh to obtain initial access_token
2017-03-12T16:36:01 (+0100) 17518 INFO _do_refresh_request (client.py:772) Refreshing access_token
2017-03-12T16:36:01 (+0100) 17518 INFO _do_refresh_request (client.py:799) Failed to retrieve access token: {
  "error" : "unauthorized_client",
  "error_description" : "Client is unauthorized to retrieve access tokens using this method."
}
2017-03-12T16:36:01 (+0100) 17518 ERROR main (import-mailbox-to-gmail.py:310) Can't get access token for user yaacov@goodimpact.studio
2017-03-12T16:36:01 (+0100) 17518 ERROR main (import-mailbox-to-gmail.py:348) Can't process user yaacov@goodimpact.studio
Traceback (most recent call last):
  File "./import-mailbox-to-gmail.py", line 308, in main
    service = discovery.build('gmail', 'v1', http=http)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 228, in build
    requested_url, discovery_http, cache_discovery, cache)
  File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 275, in _retrieve_discovery_doc
    resp, content = http.request(actual_url)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/transport.py", line 159, in new_request
    credentials._refresh(orig_request_method)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 744, in _refresh
    self._do_refresh_request(http)
  File "/usr/local/lib/python2.7/site-packages/oauth2client/client.py", line 812, in _do_refresh_request
    raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
HttpAccessTokenRefreshError: unauthorized_client: Client is unauthorized to retrieve access tokens using this method.
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:349) *** Done importing all users from directory './'
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:350) *** Import summary:
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:352)     0 users imported with no failures
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:354)     0 users imported with some failures
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:356)     1 users failed
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:358)     0 labels (mbox files) imported with no failures
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:360)     0 labels (mbox files) imported with some failures
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:362)     0 labels (mbox files) failed
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:364)     0 messages imported successfully
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:366)     0 messages failed

2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:369) *** Check log file import-mailbox-to-gmail-17518.log for detailed errors.
2017-03-12T16:36:01 (+0100) 17518 INFO main (import-mailbox-to-gmail.py:370) Finished.

If you see "Client is unauthorized to retrieve access tokens using this method", it indicates one of the following things:

  1. The client ID (usually just a number) isn't authorized in your domain's Admin console.
  2. The client ID is authorized, but some or the scopes are missing or incorrect.
  3. The client ID is authorized with the correct scopes, but not enough time has passed (like I said, usually it's less than an hour).

Please verify that you followed steps 16 and on from https://github.com/google/import-mailbox-to-gmail, and that you copied the Client ID field correctly. I'm asking about this because a common mistake is to enter something else instead of the client ID, like the service account name, or the service account email address.

Thanks!

Thanks @eesheesh for your reply.
I finally found the solution here
The response from Bryan:

The .mbox file you're looking for to import is inside the "xxxx.mbox" directory created by your Apple Mail export.

Thanks for the update! I'll close this now, based on your report. If you encounter any errors, please update this issue or create a new one, as needed.

Please verify... you copied the Client ID field correctly. I'm asking about this because a common mistake is to enter something else instead of the client ID, like the service account name, or the service account email address.

I'm leaving this comment because I've noticed that when you enter the service account email address, the console actually correctly identifies the Client ID and displays that as the client name. Don't let that trick you into actually thinking it worked, though. You need to actually enter the Client ID yourself.