Okta api python sdk抛出json错误

时间:2015-06-09 22:55:32

标签: okta okta-api

我正在尝试使用python sdk创建用户。当我运行我的脚本时,我收到以下错误:

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/sitepackages/oktasdk-python/okta/framework/ApiClient.py", line 53, in post
if self.__check_response(resp, attempts):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/sitepackages/oktasdk-python/okta/framework/ApiClient.py", line 88, in  __check_response
raise OktaError(json.loads(resp.text))
okta.framework.OktaError.OktaError: The request body was not well-formed:  Could not read JSON

以下是我的代码片段:

from okta.UsersClient import UsersClient
from collections import namedtuple

def main():

    create_okta_user()


def create_okta_user():

    usersClient = UsersClient("https://example.okta.com", "0d0d0dexamplekey")
    User = namedtuple("User", ["login", "email", "firstName", "lastName"], verbose=False, rename=False)
    user = User(login="test@example.com",
            email="test@example.com",
            firstName="user",
            lastName="tester")

    usersClient.create_user(user, activate=False)

    #usersClient.activate_user(user)

main()

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试使用namedtuple,它被序列化为json列表,而不是对象。

尝试使用这样的用户模型:

from okta import UsersClient
from okta.models.user import User


def main():
    create_okta_user()

def create_okta_user():

    usersClient = UsersClient("https://example.okta.com", "0d0d0dexamplekey")

    user = User(login="test@example.com",
            email="test@example.com",
            firstName="user",
            lastName="tester")

    user = usersClient.create_user(user, activate=False)
    #usersClient.activate_user(user)

main()

http://developer.okta.com/docs/sdk/core/python_api_sdk/quickstart.html#create-a-user