Python array of base64 encode and serialized array for WHMCS

被刻印的时光 ゝ 提交于 2021-01-29 15:55:32

问题


I am trying to add new order in WHMCS.

According to documentation for AddOrder method, it is required to specify an array of base64 encoded serialized array for customfields and configoptions parameters.

Example of such method in PHP is described in example:

        array(
            'action' => 'AddOrder',
            ....
            'customfields' => array(base64_encode(serialize(array("1" => "Google"))), base64_encode(serialize(array("1" => "Google")))),
            'configoptions' => array(base64_encode(serialize(array("1" => 999))), base64_encode(serialize(array("1" => 999)))),
            ....
        )

I just wonder how to make similar construction in Python?

Tried to use pickle and base64.encode, but no success

tmp = pickle.dumps({"1": "Google"})
customfields = [base64.b64encode(tmp).decode("utf-8")]

Then I pass customfields to request body, but no success


回答1:


Don't know if this would work but you could give it a try: tmp = base64.b64encode(b'{"1": "Google"}') customfields = [base64.b64encode(tmp).decode("utf-8")]



来源:https://stackoverflow.com/questions/61796908/python-array-of-base64-encode-and-serialized-array-for-whmcs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!