[英]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': 'jsmith@test-account.com', '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': 'jsmith@test-account.com', '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当我执行上面的 python 脚本时,出现错误
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': 'jsmith@test-account.com', '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': 'jsmith@test-account.com', '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.我传递给 query_result 的输入来自 salesforce soap Api。
Please help me to resolve this issue.. Thanks in advance请帮我解决这个问题..提前致谢
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.正如你所说
from datetime import datetime
你只是导入一种方法而不是整个模块。 And you haven't imported the date
method.而且您还没有导入
date
方法。 You could also do this:你也可以这样做:
>>> from datetime import date
>>> date(2018, 9, 20)
datetime.date(2018, 9, 20)
import datetime
datetime(2018, 7, 20).date()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.