[英]Salesforce Data into Python (simple-Salesforce or salesforce-bulk)
I'm trying to load Salesforce data into a Python dataframe, so we can do all of our manipulations there.我正在尝试将 Salesforce 数据加载到 Python 数据帧中,以便我们可以在那里进行所有操作。 simple_salesforce worked with the caveat that we reached the 2,000 limit: simple_salesforce 与我们达到 2,000 限制的警告一起工作:
from simple_salesforce import Salesforce as s
eatpies = sf.query('Select Id from Case')
attrs = ['Id']
records = eatpies['records']
data = {}
for rec in records:
for k in attrs:
data.setdefault(k, []).append(rec[k])
dframe = pd.DataFrame(data)
print(dframe)
Supposedly, salesforce-bulk ( https://pypi.python.org/pypi/salesforce-bulk/1.0.7 ) is able to bypass this limit, but I can't get further than this:据说,salesforce-bulk ( https://pypi.python.org/pypi/salesforce-bulk/1.0.7 ) 能够绕过这个限制,但我不能比这更进一步:
job = bulk.create_query_job("Case", contentType='CSV')
batch = bulk.query('select Id, type from Case')
TypeError Traceback (most recent call last)
<ipython-input-13-076e14bf245d> in <module>()
----> 1 batch = bulk.query('select Id, type from Case')
TypeError: query() missing 1 required positional argument: 'soql'
Please help, thanks!请帮忙,谢谢! If the solution can be done in simple-Salesforce to over-come the Salesforce limit, that would be great, but I couldn't find any solutions via Google.如果解决方案可以在 simple-Salesforce 中完成以克服 Salesforce 的限制,那就太好了,但我无法通过 Google 找到任何解决方案。
Change the line换线
eatpies = sf.query('Select Id from Case')
to the following:到以下几点:
eatpies = sf.query_all('Select Id from Case')
The method query_all a convenience wrapper around query(...)
and query_more(...)
.方法 query_all 是query(...)
和query_more(...)
的便捷包装器。
From the docs:从文档:
If, due to an especially large result, Salesforce adds a nextRecordsUrl to your query result, such as "nextRecordsUrl" : "/services/data/v26.0/query/01gD0000002HU6KIAW-2000", you can pull the additional results with either the ID or the full URL (if using the full URL, you must pass 'True' as your second argument)如果由于结果特别大,Salesforce 将 nextRecordsUrl 添加到您的查询结果中,例如 "nextRecordsUrl" : "/services/data/v26.0/query/01gD0000002HU6KIAW-2000",您可以使用ID 或完整 URL(如果使用完整 URL,则必须传递 'True' 作为第二个参数)
sf.query_more("01gD0000002HU6KIAW-2000")
sf.query_more("/services/data/v26.0/query/01gD0000002HU6KIAW-2000", True)
You also have access to Bulk API through simple-salesforce.您还可以通过 simple-salesforce 访问批量 API。 For example, replace例如,替换
eatpies = sf.query('Select Id from Case')
attrs = ['Id']
records = eatpies['records']
with the following:具有以下内容:
eatpies = sf.bulk.Case.query('Select Id from Case')
attrs = ['Id']
records = eatpies
More information about using Bulk API: https://github.com/simple-salesforce/simple-salesforce#using-bulk有关使用批量 API 的更多信息: https : //github.com/simple-salesforce/simple-salesforce#using-bulk
sf.query_all("select count(Id) from visitors where CreatedDate >= 2017-12-01T00:00:00.000+0000 and CreatedDate < 2019-01-01T00:00:00.000+0000", True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.