Skip to main content
 首页 » 编程设计

Python Simple_Salesforce 关闭连接

2025年05月04日15sharpest

我最近才开始使用 Python 的 Simple_Saleforce 包 https://pypi.python.org/pypi/simple-salesforce

我想知道您登录后连接会持续多长时间?有没有手动关闭()连接的方法?我已经查看了文档和源代码,但也许我错过了这个小细节。

作为上下文,我正在构建一个 celery 任务以每隔几分钟轮询一次 salesforce,并且想知道我是否需要在每次轮询时重新打开连接(即登录),或者全局登录是否足够(多长时间)?

谢谢!

请您参考如下方法:

来自 simple-salesforce 库使用的 SalesFOrce REST API:

Access tokens have a limited lifetime specified by the session timeout in Salesforce. If an application uses an expired access token, a “Session expired or invalid” error is returned. If the application is using the Web server or user-agent OAuth authentication flows, a refresh token may be provided during authorization that can be used to get a new access token.

是的,您的 session 有超时,您可以根据文档在您的 SalesForce 上设置它:

The session timeout for an access token can be configured in Salesforce from Setup by clicking Security Controls | Session Settings.

所以是的,一旦您的 session 超时,您必须请求一个新的 session ID。如果你想手动关闭连接,你可以通过设置它的年龄来销毁 session :session.setMaxAge(-1)。

链接到 full documentation

希望这对您有所帮助,干杯!