1
votes

I am sure there are easier ways to do this, but I am not sure why I keep getting a TypeError.

   import datetime
   getdate = datetime.date.today()
   thirty = datetime.timedelta(days=30)
   last_month = getdate - thirty
   print json.dumps(api.get_zone_stats(3, "daily", "%s", "%s" %(last_month, getdate)))

Traceback (most recent call last): ...

TypeError: not all arguments converted during string formatting

2

2 Answers

3
votes

The problem is here:

api.get_zone_stats(3, "daily", "%s", "%s" %(last_month, getdate))

The % operator works on the previous string only:

"%s" %(last_month, getdate)

You have two variables for one single %s.

Try this:

api.get_zone_stats(3, "daily", "{0}".format(last_month), "{0}".format(getdate))

or this:

api.get_zone_stats(3, "daily", str(last_month), str(getdate))
0
votes

In your last line, you're trying to format a string with two values but the string contains only one fill-in-spot:

print json.dumps(api.get_zone_stats(3, "daily", "%s", "%s" %(last_month, getdate)))

Did you mean the following?

print json.dumps(api.get_zone_stats(3, "daily", str(last_month), str(getdata)))