Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'int'

import beatbox
import pandas as pd
import numpy as np
from simple_salesforce import Salesforce
from datetime import *
import datetime as dt
import mysql.connector
from mysql.connector import Error
from datetime import datetime
query_result= [{'End_Date__c': datetime.date(2018, 7, 20), 'User_Email__c': '[email protected]', 'ProductVersion__c': '1', 'Product_Name__c': 'Payor', 'itil_b__Account__r': {'type': 'Account', 'Id': '', 'Customer_Short_Name__c': 'TESTACCT'}, 'Target_Environment__r': {'type': 'Environment__c', 'Id': '', 'Name': 'TEST-PROD'}, 'type': 'itil_b__Fulfillment__c', 'Id': 'a3sc0000000CiZpAAK'}, {'End_Date__c': datetime.date(2018, 7, 19), 'User_Email__c': '[email protected]', 'ProductVersion__c': '4', 'Product_Name__c': 'CareManager', 'itil_b__Account__r': {'type': 'Account', 'Id': '', 'Customer_Short_Name__c': 'TESTACCT'}, 'Target_Environment__r': {'type': 'Environment__c', 'Id': '', 'Name': 'TEST-NONPROD'}, 'type': 'itil_b__Fulfillment__c', 'Id': 'a3sc0000000CiAyAAK'}]

record=query_result['records']
df=pd.DataFrame(records)
print df

When I execute above python script, I am getting error

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    query_result= [{'End_Date__c': datetime.date(2018, 7, 20), 'User_Email__c': '[email protected]', 'ProductVersion__c': '1', 'Product_Name__c': 'Payor', 'itil_b__Account__r': {'type': 'Account', 'Id': '', 'Customer_Short_Name__c': 'TESTACCT'}, 'Target_Environment__r': {'type': 'Environment__c', 'Id': '', 'Name': 'TEST-PROD'}, 'type': 'itil_b__Fulfillment__c', 'Id': 'a3sc0000000CiZpAAK'},  {'End_Date__c':datetime.date(2018, 7, 19), 'User_Email__c': '[email protected]', 'ProductVersion__c': '4', 'Product_Name__c': 'CareManager','itil_b__Account__r': {'type': 'Account', 'Id': '', 'Customer_Short_Name__c': 'TESTACCT'}, 'Target_Environment__r': {'type': 'Environment__c', 'Id': '', 'Name': 'TEST-NONPROD'}, 'type': 'itil_b__Fulfillment__c', 'Id': 'a3sc0000000CiAyAAK'}]
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'int'

The input I am passing to query_result got from a salesforce soap Api.

Please help me to resolve this issue.. Thanks in advance

like image 604
Ram Avatar asked Jul 28 '17 19:07

Ram


People also ask

How do I convert a date to a string in Python?

To convert Python datetime to string, use the strftime() function. The strftime() method is a built-in Python method that returns the string representing date and time using date, time, or datetime object.

How do you create a time object in Python?

To create a time object, we use the time class in the datetime module using the statement, datetime. time(hour, minutes, seconds), where hour is the hour, minutes is the minutes, and seconds is the seconds.

How do you compare datetime dates?

Compare() method in C# is used for comparison of two DateTime instances. It returns an integer value, <0 − If date1 is earlier than date2. 0 − If date1 is the same as date2.


1 Answers

Change your import statement from:

from datetime import datetime

to

import datetime

As when you say from datetime import datetime you are just importing one method and that and not the whole module. And you haven't imported the date method. You could also do this:

>>> from datetime import date
>>> date(2018, 9, 20)
datetime.date(2018, 9, 20)
like image 51
anon Avatar answered Oct 04 '22 06:10

anon