I am attempting to write an app in Python to allow users to migrate their LISTSERV archives to Google Groups for our domain. When attempting to call archive.insert (https://developers.google.com/admin-sdk/groups-migration/v1/reference/archive/insert), I receive an HttpError 500 "Backend Error".
I am reading in the archive like so:
import mailbox
mailbox.mbox('path/to/archive')
When iterating through the resulting messages in the mbox object, calling the .as_string() function results in something like this:
Date: Mon, 10 Feb 2014 10:58:41 -0600
Reply-To: Bob's test list <BOB@LISTSERV.DOMAIN.COM>,
Bob Boberson <bob@EXCHANGE.DOMAIN.COM>
Sender: Bob's test list <BOB@LISTSERV.DOMAIN.COM>
From: Bob Boberson <bob@EXCHANGE.DOMAIN.COM>
Subject: blah blah blah
Mime-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="UTF-8"
Message-ID: <6949565692507828.WA.bobexchange.domain.com@listserv.domain.com>
Test message.
Some questions here mention avoiding backend errors by ensuring that the Message-ID is in the correct format. However, message['Message-ID'] for this particular message results in <6949565692507828.WA.bobexchange.domain.com@listserv.domain.com>, so I'm not sure Message-ID is the issue here.
I am attempting to call insert like so:
stream = StringIO.StringIO()
stream.write(msg.as_string())
media = apiclient.http.MediaIoBaseUpload(stream, mimetype='message/rfc822')
result = migration_api.archive().insert(groupId=group_email, media_body=media).execute()
Any ideas? Thanks in advance :)
UPDATE
According to Jay's suggestion in the comments, I have set httplib2.debuglevel = 1. Here is the result in my logs of attempting to migrate the same email:
send: 'POST /upload/groups/v1/groups/group-name%40lists.domain.com/archive?uploadType=media&alt=json HTTP/1.1\r\nHost: www.googleapis.com\r\ncontent-length: 711\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: google-api-python-client/1.4.0 (gzip)\r\ncontent-type: message/rfc822\r\nauthorization: Bearer *******\r\n\r\nDate: Mon, 10 Feb 2014 10:58:41 -0600\nReply-To: Bob\'s test list <GROUP-NAME@LISTSERV.DOMAIN.COM>,\n Bob Boberson <bob@EXCHANGE.DOMAIN.COM>\nSender: Bob\'s test list <bob@LISTSERV.DOMAIN.COM>\nFrom: Bob Boberson <bob@EXCHANGE.DOMAIN.COM>\nSubject: blah blah blah\nMime-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nContent-Type: text/plain; charset="UTF-8"\nMessage-ID: <6949565692507828.WA.bobexchange.domain.com@listserv.domain.com>\n\n\nTest message.'
reply: 'HTTP/1.1 500 Internal Server Error\r\n'
header: X-GUploader-UploadID: *****
header: Vary: Origin
header: Vary: X-Origin
header: Content-Type: application/json; charset=UTF-8
header: Content-Length: 177
header: Date: Wed, 23 Mar 2016 21:10:20 GMT
header: Server: UploadServer
header: Alternate-Protocol: 443:quic,p=1
header: Alt-Svc: quic=":443"; ma=2592000; v="31,30,29,28,27,26,25"
UPDATE (with solution)
It turns out this was a permissions issue: When going the domain-wide service account route, be sure to impersonate the user who owns the group. FWIW, IMHO, the error messages for the Groups Migration API need to be a little more explicit about what the problem is. "Backend Error" is horribly generic. Figuring this out was like poking at the problem with a stick until it works.