Python [2.7]中的新手功能不起作用

时间:2017-01-23 12:36:56

标签: python

我正在使用我从网上下载的脚本来访问我们的服务API。 我正在尝试运行该函数,但无论我想做什么,都会不断出错。

from PyBambooHR import PyBambooHR

bamboo = PyBambooHR(subdomain='domain', api_key='apicode')
changes = bamboo.get_employee_changes()

当我运行它时,我收到以下错误:

  

ValueError:错误:因为参数必须是datetime.datetime实例

现在,无论我设置什么参数,我仍然会遇到错误。我还尝试了以下语法:https://www.bamboohr.com/api/documentation/changes.php

功能是:

def get_employee_changes(self, since=None):
    """
    Returns a list of dictionaries, each with id, action, and lastChanged keys, representing
    the employee records that have changed since the datetime object passed in the since= argument.

    @return List of dictionaries, each with id, action, and lastChanged keys.
    """
    if not isinstance(since, datetime.datetime):
        raise ValueError("Error: since argument must be a datetime.datetime instance")

    url = self.base_url + 'employees/changed/'
    params = {'since': since.strftime('%Y-%m-%dT%H:%M:%SZ')}
    r = requests.get(url, params=params, headers=self.headers, auth=(self.api_key, ''))
    r.raise_for_status()

    return utils.transform_change_list(r.content)

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

正如您所看到的,该函数是一个参数,因为类型为 datetime.datetime

OS_DOMAIN_ID

应该给你去年以来的变化

答案 1 :(得分:0)

在调用函数datetime.datetime

时传递bamboo.get_employee_changes()类型的变量