我正在努力创建使用 Vault API 导出的 Gmail。我已成功完成快速启动过程。我可以成功地创建和列出事项。当我尝试创建 Gmail 导出时,我收到以下错误。
C:\Users\ron\Documents\google>createGmailExport.py --matter_Id 78978b7-9fe8-4bdd-84c7-bbf22cd1234 --gmail_account ron@ron.com --export_name ratest
Namespace(export_name='ratest', matter_Id='78978b7-9fe8-4bdd-84c7-bbf22cd1234', gmail_account='ront@ron.com')
Traceback (most recent call last):
File "C:\Users\ron\Documents\google\createGmailExport.py", line 95, in <module>
create_mail_account_held_data_export(valutService,cliArgs)
File "C:\Users\ron\Documents\google\createGmailExport.py", line 88, in create_mail_account_held_data_export
return service.matters().exports().create(matterId=args.matter_Id, body=wanted_export).execute()
File "C:\Users\ron\AppData\Local\Programs\Python\Python39\lib\site-packages\googleapiclient\_helpers.py", line 131, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\ron\AppData\Local\Programs\Python\Python39\lib\site-packages\googleapiclient\http.py", line 937, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://vault.googleapis.com/v1/matters/78978b7-9fe8-4bdd-84c7-bbf22cd1234/exports?alt=json returned "Emails do not exist:
[email1, email2]". Details: "Emails do not exist:
[email1, email2]">
源代码:
#!/usr/bin/python
from __future__ import print_function
from http import server
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
import os.path
import re
import sys
import getopt
import argparse
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/ediscovery']
def main():
"""Shows basic usage of the Vault API.
Prints the names and IDs of the first 10 matters in Vault.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('vault', 'v1', credentials=creds)
return service
#Setup Args.
def get_args():
# Create the parser
parser = argparse.ArgumentParser(
description='''This script creates a Valut matter.''',
epilog='''Please contact Ron at ron@ron.com'''
)
# Add an argument
parser.add_argument('--export_name', type=str, required=True)
parser.add_argument('--matter_Id', type=str, required=True)
parser.add_argument('--gmail_account', type=str, required=True)
# Parse the argument
args = parser.parse_args()
return args
#Call valut API
def create_mail_account_held_data_export(service, args):
emails_to_search = ['email1', 'email2']
mail_query_options = {'excludeDrafts': True}
query_terms = args.gmail_account
mail_query = {
'corpus': 'MAIL',
'dataScope': 'HELD_DATA',
'searchMethod': 'ACCOUNT',
'accountInfo': {
'emails': emails_to_search
},
'terms': query_terms,
'mailOptions': mail_query_options,
}
mail_export_options = {
'exportFormat': 'MBOX',
'showConfidentialModeContent': True
}
wanted_export = {
'name': args.export_name,
'query': mail_query,
'exportOptions': {
'mailOptions': mail_export_options
}
}
return service.matters().exports().create(matterId=args.matter_Id, body=wanted_export).execute()
#Call main
if __name__ == '__main__':
valutService = main()
cliArgs = get_args()
create_mail_account_held_data_export(valutService,cliArgs)