I'm trying to retrieving free/busy status from outlook calender for particular person using python language.
here is my code for it.
import win32com.client
obj_outlook = win32com.client.Dispatch('Outlook.Application')
obj_Namespace = obj_outlook.GetNamespace("MAPI")
obj_Recipient = obj_Namespace.CreateRecipient("someone@domain.com")
str_Free_Busy_Data = obj_Recipient.FreeBusy("11-11-2013", 11)
print str_Free_Busy_Data
but I'm getting an error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
str_Free_Busy_Data = obj_Recipient.FreeBusy("11-11-2013", 11)
File "<COMObject CreateRecipient>", line 4, in FreeBusy
TypeError: an integer is required
So my question is Recipient.FreeBusy() method takes two mandatory arguments, Start Date and duration. Here 11 is the duration, which is an Integer. So why python is not able to identify the integer argument here and returning an TypeError.
Please help me in case I have done anything wrong (I'm still a newbie in python world).
Thanks in advance.
I looked up the method in MSDN.
http://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.outlook.recipient.freebusy(v=office.12).aspx
The syntax for the method takes 3 arguments.
)
The issue is that you're passing a string to the DateTime parameter. Instead you need to import the datetime library in your code and use a date parameter.
So, at the start of your code, try this.
The first parameter to
FreeBusy
is aDate
object. Pywin won't convert a string into aDate
, but it can convert apywintypes.Time
object, or an integer representing the number of seconds since the Unix epoch. Hence the error: When the first argument is implicitly converted to aTime
, the constructor complains that it needs an integer.There are a number of ways to get the Unix timestamp from a date. See Convert python datetime to epoch with strftime.