GAM 3.0.4 "gam user xyz show calendars" and Service Account Error

1,068 views
Skip to first unread message

S. Joyce

unread,
Feb 6, 2014, 11:37:24 AM2/6/14
to google-ap...@googlegroups.com
Hello.

I'm trying to make use of the new Calendar features in GAM 3.0.4 (Linux).

The normal GAM 3.0.4 commands work fine (e.g. "gam info domain"), and we're running our own "client_secrets.json" file (per https://code.google.com/p/google-apps-manager/wiki/CreatingClientSecretsFile).  We've been running that way for a while with no problems.

This morning, I attempted (twice) to set up a service account in order to use the new Calendar commands, following (https://code.google.com/p/google-apps-manager/wiki/GAM3OAuthServiceAccountSetup).  I am able to create the service account in the Google API Console fine.  I download the private key and rename it to "oauth2service.p12" (per Jay's instructions).  I also use the Google Apps Control Panel to authorize the client and API scopes per the instructions.

When I then run

gam user x...@xyz.com show calendars

I am not prompted for the email address of my service account.  Instead, I see 

Error: [Errno 2] No such file or directory: '/root/oauth2service.json'
Please follow the instructions at:
https://code.google.com/p/google-apps-manager/wiki/GAM3OAuthServiceAccountSetup
to setup a Service Account

Thinking that perhaps it's a file naming issue, I copy "oauth2service.p12" to "oauth2service.json" (even though it's not a JSON, file, right?)  If I then run the "show calendars" command again,  I see this error:

[root@sam ~]# gam user sjoyce show calendars

Traceback (most recent call last):
  File "gam.py", line 6499, in <module>
    showCalendars(users)
  File "gam.py", line 1456, in showCalendars
    cal = buildGAPIServiceObject('calendar', user)
  File "gam.py", line 559, in buildGAPIServiceObject
    json_data = json.loads(json_string)
  File "/usr/lib/python2.7/json/__init__.py", line 310, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 349, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 1 - line 8 column 234 (char 1 - 1668)

If instead I use the API console to "Download JSON" and put that file (as "oauth2service.json") alongside the real "oauth2service.p12" (thinking maybe the instructions missed a step about downloading a JSON file), I see this error: 


Traceback (most recent call last):
  File "gam.py", line 6499, in <module>
    showCalendars(users)
  File "gam.py", line 1456, in showCalendars
    cal = buildGAPIServiceObject('calendar', user)
  File "gam.py", line 593, in buildGAPIServiceObject
    return apiclient.discovery.build(api, version, http=http)
  File "/root/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/root/apiclient/discovery.py", line 196, in build
    resp, content = http.request(requested_url)
  File "/root/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/root/oauth2client/client.py", line 475, in new_request
    self._refresh(request_orig)
  File "/root/oauth2client/client.py", line 653, in _refresh
    self._do_refresh_request(http_request)
  File "/root/oauth2client/client.py", line 677, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/root/oauth2client/client.py", line 861, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/root/oauth2client/client.py", line 977, in _generate_assertion
    private_key, self.private_key_password), payload)
  File "/root/oauth2client/crypt.py", line 294, in make_signed_jwt
    signature = signer.sign(signing_input)
  File "/root/oauth2client/crypt.py", line 112, in sign
    return crypto.sign(self._key, message, 'sha256')
AttributeError: 'module' object has no attribute 'sign'


I have repeated the entire process twice and have the same error.  I'm afraid I'm missing something extremely simple.

TIA if anyone can offer any suggestions.  Again, GAM 3.0.4, Linux.


-

S. Joyce

Dan Schwartz

unread,
Feb 6, 2014, 3:07:45 PM2/6/14
to google-ap...@googlegroups.com
Hi S. Joyce,

Do you have an oauth2service.txt file that has the email that goes along with the .p12 file?  Perhaps that's what you need.  I have one which has a "large number"@developer.gserviceaccount.com in it.

I also have a "client_secrets.json" and oauth2.txt files to round out the "special" files that are used for configuring gam.

I've just been copying those 4 files over with the new releases (3.0x) and it all seems to keep working.



--
Dan Schwartz | LTS - Systems and Networking  | Lehigh University | da...@lehigh.edu | (610) 758-5061


--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/ed396b3e-e8c2-4f8d-b2a9-4bced01403d4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sean Joyce

unread,
Feb 6, 2014, 3:39:32 PM2/6/14
to google-ap...@googlegroups.com
Dan,

Thanks...I don't have an "oauth2service.txt" file, although I do have the "client_secrets.json" and "oauth2.txt" files that seem to make the "normal" GAM calls work.

If I create an "oauth2service.txt" file with the email address of this (new) service account, I still get the same error when I try to run "gam user xyz show calendars":

Error: [Errno 2] No such file or directory: '/root/oauth2service.json'
Please follow the instructions at:
https://code.google.com/p/google-apps-manager/wiki/GAM3OAuthServiceAccountSetup
to setup a Service Account

Still at a loss...

Sean Joyce





Sean Joyce

unread,
Feb 6, 2014, 4:09:45 PM2/6/14
to google-ap...@googlegroups.com
Ah....I may be running up against a Python version issue and maybe missing the PyOpenSSL and PyCrypto libraries (from one of your earlier posts, Dan).

I'll see if I can make a parallel installation of GAM on a new machine with more recent Python and see what happens.

Sean

NicholasT

unread,
Feb 16, 2014, 7:43:26 PM2/16/14
to google-ap...@googlegroups.com
I'm getting exactly the same problem.  I've set this up before and got it working but I remember it was not as straight-forward as it should have been.  

Could someone post the exact files that should be in the GAM folder and where to source them as this is frustrating (trying to wipe a calendar) as I can't remember what I did last time.

Having the Google API console project setup, the necessary API enabled (Calendar API for me) and downloading the JSON as client_secrets.json into the GAM folder does not do it.  

I also get Error: [Errno 2] No such file or directory: '/root/oauth2service.json'

Thanks,
Nicholas
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.

To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

Dan Schwartz

unread,
Feb 17, 2014, 8:49:37 AM2/17/14
to google-ap...@googlegroups.com
Hi Nicholas,

I was just having the same problem, but solved it by creating a oauth2service.json file by logging into the api interface (https://code.google.com/apis/console), and following the instructions here - https://code.google.com/p/google-apps-manager/wiki/GAM3OAuthServiceAccountSetup - with some minor changes.  I already had most of it setup.  I just had to download the json file as shown by this screen shot.  Click the "download json" button for the service account.  It saves it as client_secret_(whatever your id is).apps.googleusercontent.com.json.  Rename that file as oauth2service.json and put it into the gam directory and then try it out again.  Remember you needed to authorize your client id with the google admin console for calendar (and drive access) as well as do the setup steps in the developers console.

Inline image 2

Hope that helps you out.  - Dan

--
Dan Schwartz | LTS - Systems and Networking  | Lehigh University | da...@lehigh.edu | (610) 758-5061


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.

To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

Yves Mainville

unread,
Apr 30, 2014, 9:52:25 PM4/30/14
to google-ap...@googlegroups.com
Excellent!!
This cured the problem for me... I should have figured it out from setting up GAM initially.
So that wiki page needs to be updated to have this last bit in there... "Download the xxxxxxxxxxxx.json file into the GAM folder, rename it to 'oauth2service.json' " and 'whoop, there it is'.

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsubscribe...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsubscribe...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

David Naylor

unread,
May 7, 2014, 6:30:15 PM5/7/14
to google-ap...@googlegroups.com
I went through the whole guide there, and also found missing json file and got that added to my gam.py directory (on a mac), but i am still getting errors

----

gam user xx...@xxxx.com show filelist allfields

Getting files for xx...@xxxx.com...

Error 401: Invalid Credentials - authError
----

David Naylor

unread,
May 7, 2014, 6:32:56 PM5/7/14
to google-ap...@googlegroups.com
And now that i think about it.  Step 14 of that guide, it never actually prompts me for the email address of my service account.  Could be the issue?

Scott S

unread,
May 14, 2014, 10:18:04 AM5/14/14
to google-ap...@googlegroups.com
I followed the instructions on https://code.google.com/p/google-apps-manager/wiki/GAM3OAuthServiceAccountSetup and downloaded the json, renamed to oauth2service.json and get the following error.

C:\gam>gam user <user> show calendars
Traceback (most recent call last):
  File "gam.py", line 6499, in <module>
  File "gam.py", line 1456, in showCalendars
  File "gam.py", line 559, in buildGAPIServiceObject
  File "json\__init__.pyo", line 338, in loads
  File "json\decoder.pyo", line 368, in decode
ValueError: Extra data: line 1 column 2 - line 3 column 12 (char 1 - 101)

Scott S

unread,
May 14, 2014, 10:20:59 AM5/14/14
to google-ap...@googlegroups.com
I got it to work.  The initial p12 file I renamed as oauth2service.p12 and then had to go back and download the json file and rename to oauth2service.json.  Works great now.  I was also not prompted for the service email address.


On Thursday, February 6, 2014 11:37:24 AM UTC-5, S. Joyce wrote:

Jason P.

unread,
Jun 25, 2014, 5:40:53 PM6/25/14
to google-ap...@googlegroups.com
I got it to work now also, but when I use the parameter     color  #2952A3      it goes into an infinite loop, spitting out the message below, and I have to control-C to kill it...

        color is not a valid argument for "gam add calendar"

Thanks for the tips Scott.

Jason P

Steven Gilman

unread,
Aug 15, 2014, 12:11:58 PM8/15/14
to google-ap...@googlegroups.com
I don't get that prompt either and I don't have an oauth2service.txt file.  Is that perhaps the step that creates that file?  How else could I get that file.  

Instead of being prompted I get:

Traceback (most recent call last):
  File "gam.py", line 7249, in <module>
  File "gam.py", line 1620, in showCalendars
  File "gam.py", line 573, in buildGAPIServiceObject
KeyError: u'web'

Brian Candler

unread,
Sep 2, 2014, 1:04:48 AM9/2/14
to google-ap...@googlegroups.com
I'm getting the exact same error. 
Key Error: u'web' on line 573

I'm seeing some discrepancies in my experience and what is described in this thread.
For example, when the json private key file is downloaded, it doesn't save as "client_secret_<id>". It saves it as the API Project name with a number.  
I only mention this because I've followed the above directions and am still getting this key error.  Since the API console experience has changed, could there be other changes that might affect setting up a service account for GAM?

FINAL EMAIL SIGNATURE - STAFF.png
This message is private and confidential and is intended only for the use of the individual or entity named above. If you have received this message in error, please notify the International School of Kuala Lumpur (ISKL) and remove it from your system. Unless it relates to the official business of ISKL, any opinions or matters expressed in this message are those of the individual sender. As noted in our Acceptable Use Policy, ISKL may monitor email traffic data.

Michel Fasen

unread,
Sep 15, 2014, 5:22:07 AM9/15/14
to google-ap...@googlegroups.com
I had the same issue but then decided to follow the Installation Doc by Brian from the start, including extracting a fresh copy of GAM and creating a new project with the old console. Only then I got it working.

Before that I tried to create a new Client ID in the already created project and constantly got the same error like you have (Key Error: u'web' ), so I highly recommend to make a fresh start with a new project.

Rex Roof

unread,
Oct 9, 2014, 3:21:51 PM10/9/14
to google-ap...@googlegroups.com
Why isn't the information in this Installation Doc in the wiki?  Also, it is very frustrating that the old wiki links all lead to dead ends.  And the new wiki apparently isn't searchable?


I just followed these steps in order to get "gam user xxx show filelist" to work as it was erroring due to missing oauth2service.json.

Now, after following all of those steps, I get this traceback:


Traceback (most recent call last):
  File "gam.py", line 7510, in <module>
    showDriveFiles(users)
  File "gam.py", line 1840, in showDriveFiles
    drive = buildGAPIServiceObject(u'drive', user)
  File "gam.py", line 621, in buildGAPIServiceObject
    return apiclient.discovery.build(api, version, http=http)
  File "/home/r/e/rex/gam/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/r/e/rex/gam/apiclient/discovery.py", line 196, in build
    resp, content = http.request(requested_url)
  File "/home/r/e/rex/gam/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/r/e/rex/gam/oauth2client/client.py", line 475, in new_request
    self._refresh(request_orig)
  File "/home/r/e/rex/gam/oauth2client/client.py", line 653, in _refresh
    self._do_refresh_request(http_request)
  File "/home/r/e/rex/gam/oauth2client/client.py", line 677, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/home/r/e/rex/gam/oauth2client/client.py", line 861, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/home/r/e/rex/gam/oauth2client/client.py", line 977, in _generate_assertion
    private_key, self.private_key_password), payload)
  File "/home/r/e/rex/gam/oauth2client/crypt.py", line 294, in make_signed_jwt
    signature = signer.sign(signing_input)
  File "/home/r/e/rex/gam/oauth2client/crypt.py", line 112, in sign
    return crypto.sign(self._key, message, 'sha256')
AttributeError: 'module' object has no attribute 'sign'


Anyone have pointers?

Rex Roof

unread,
Oct 10, 2014, 9:40:46 AM10/10/14
to google-ap...@googlegroups.com
I was able to get past this error by trying this again from a new machine with a fresh GAM install.  
I re-did the steps in the Installation Doc and I had to install the pyOpenSSL package. 

Now I'm getting this error:
Error 403: Access Not Configured. Please use Google Developers Console to activate the API for your project. - accessNotConfigured

I have Drive API and Drive SDK enabled in my Developer's Console and I have them authorized within the Admin Panel. 

here is the full output from my gam command:


$ gam user r...@wccnet.edu show filelist todrive
Getting files for r...@wccnet.edu...
 got 182 files for r...@wccnet.edu...
Error 403: Access Not Configured. Please use Google Developers Console to activate the API for your project. - accessNotConfigured

Rex Roof

unread,
Oct 10, 2014, 10:26:00 AM10/10/14
to google-ap...@googlegroups.com
I got this working by removing the "todrive" from the end.  

FYI, a newly downloaded GAM-3.41 still lists the old wiki URL.

It would be really nice if there were a nice list of available commands from within the gam executable itself. 
Nothing too detailed, but the syntax is always tricky and apparently variable. 
Reply all
Reply to author
Forward
0 new messages