str(int(time.time()))给出错误字符串索引必须是python 3中的整数

时间:2017-08-24 13:51:55

标签: python-3.x time nonce

我是python新手我为我的网站API创建了一个python pip包我需要传递nonce。我写下面的代码

payload = {}
        headers = {}

        if self.api_key is not None:
            payload["api_key"] = self.api_key 

        if self.secret_key is not None:
            payload["secret_key"] = self.secret_key

            payload["request"] = method


            payload["nonce"] = str(int(time.time()))



        payload.update(kwargs)

        headers["X-WCX-APIKEY"] = self.api_key
        headers["X-WCX-PAYLOAD"] = base64.b64encode(json.dumps(payload).encode('utf-8'))
        headers["X-WCX-SIGNATURE"] = 'SIGNATURE'
              url = self.base_url.replace('API_CALL',method)

        # update the parameters with the API key
        session = requests.session()
        response = session.post(url, data = payload, headers = headers)

运行此代码时出现此错误"字符串索引必须为整数"

我如何解决它,请帮助任何人

注意我导入"时间"

0 个答案:

没有答案