无法通过 googleapiclient 设置密码

Trouble setting password via googleapiclient

我在通过 Python Google API 设置密码时遇到问题。以下是我正在做的事情的总结:

from googleapiclient import build
import hashlib

password = 'secret'
hashed_password = hashlib.sha1(password).hexdigest()
params = {'password': hashed_password}

# 'http' is a httplib2.Http() object with the appropriate credentials to
# access the Google API
directory = build('admin', 'directory_v1', http=http)

username = 'batman@batcave.org'
directory.users().update(userKey=username, body=params).execute()

代码执行无任何错误,但密码未设置为预期值。

我需要告诉 API 密码是用 SHA-1 散列的吗?如果可以,怎么做?

这似乎可以解决问题:

params = {'password': hashed_password, 'hashFunction': 'SHA-1'}