Str对象不可调用错误

时间:2015-07-08 14:48:09

标签: python python-2.7

我不熟悉TypeError:' str' object不可调用错误。这令人沮丧,因为这段代码一直在用到今天,我还没有改变与这种方法直接相关的任何东西。

Python所说的行是罪魁祸首:

    start_date = date(2015, 5, 20)

整个方法:原谅鸡的划痕评论。

def daterange(start_date, end_date):
    for n in range(int ((end_date - start_date).days)):
        yield start_date + timedelta(n)

#DOESN'T FETCH ALL THE DOMAINS FOR WHATEVER REASON
#Search for new domains, written by Todd
#1. add to a running set, 'grabbedDomains' 2. add output file for each day run 3. write to master CSV 
def domainSearch(search_term):
    """
    Function registrant_monitor_data_details provides searching over a range of dates, this allows script to be ran once a week or at whatever
    interval we need.  May or may not need de-duplicating, will find out during testing.
    """
    #Today's date; date of domains we're searching for
    start_date = date(2015, 5, 20)
    end_date = date(2015, 6, 26)
    #single_date.strftime("%Y-%m-%d") 
    for single_date in daterange(start_date, end_date):
    #today = time.strftime("%Y-%m-%d")
        results = client.registrant_monitor_data_details(date= single_date.strftime("%Y-%m-%d"), term=search_term)
        data = results['data']
        if type(data) is dict:
            for alert in results['data']['alerts']:
                print "{0} - {1}".format(alert['domain'], alert['created'])
                #Adds domains to the global set to be added to the case
                global domainList
                domainList.append("{0}".format(alert['domain']))
    #Gets domain details from DIPITS by date and search term (email address), RETURNS DICTIONARY

    #Prints search results, should be domains registered by search term
    print "LENGTH, ", len(domainList)

    return results

1 个答案:

答案 0 :(得分:4)

代码中的其他位置,您已为date分配了一个字符串。

from datetime import date  # usual import
date(2015, 7, 8)  # this works
date = "hello"  # replace date with a string
date(2015, 7, 8)  # causes TypeError
相关问题