python - 尝试为测试组织点击 Salesforce API 时出现身份验证错误
问题描述
我正在使用以下代码登录到我们的 Salesforce 组织,只要它连接到 prod 组织,代码就可以完美运行,但是一旦我将endpoint
from"https://login.salesforce.com/services/Soap/u/35.0"
更改"https://test.salesforce.com/services/Soap/u/35.0"
为连接到我们的测试组织,它就会失败并显示我的exceptionCode='INVALID_LOGIN'
.
from runcmd.java_helper import jvm
from runcmd.logging_helper import get_logger
LOGGER = get_logger(__name__)
ENDPOINT = "https://test.salesforce.com/services/Soap/u/35.0"
def authenticate(username, password, security_token) -> dict:
"""
Authenticates against salesforce.
"""
return {
"username": username,
"password": password,
"security_token": security_token
}
def _build_sf_connection(spark, sf_obj):
config = jvm(spark).com.sforce.ws.ConnectorConfig()
config.setUsername(sf_obj["username"])
config.setPassword(sf_obj["password"] + sf_obj["security_token"])
config.setAuthEndpoint(ENDPOINT)
config.setServiceEndpoint(ENDPOINT)
LOGGER.info("Username=%s" % sf_obj["username"])
return jvm(spark).com.sforce.soap.partner.Connector.newConnection(config)
我检查了登录信息,它们都是正确的,但我注意到即使我已将代码中的端点更改为 test.salesforce,它仍然试图通过 login.salesforce 进行连接。
20/05/01 06:13:58 INFO SFConfig: loginURL : https://login.salesforce.com/services/Soap/u/35.0
20/05/01 06:14:02 ERROR SFConfig: Exception while creating connection
[LoginFault [ApiFault exceptionCode='INVALID_LOGIN'
exceptionMessage='Invalid username, password, security token; or user locked out.'
extendedErrorDetails='{[0]}'
解决方案
您必须有其他设置 login.salesforce.com 的东西,也许 java 应用程序已经在 JAR 中硬编码或在他们自己的配置文件中定义......为什么它是通过 java 完成的任何特殊原因?您是否尝试过https://pypi.org/project/simple-salesforce/或https://pypi.org/project/pyforce/并认为它们不合适?
仔细看看com.sforce.soap.partner
……嗯,看起来“合作伙伴 WSDL ”已经被消费了,Java 类是由它生成的(转到设置 -> API)。您可以检查这些类并查看是否有任何内置内容可以让您在运行时覆盖基于 WSDL 底部的该片段生成的代码。
<service name="SforceService">
<documentation>Sforce SOAP API</documentation>
<port binding="tns:SoapBinding" name="Soap">
<soap:address location="https://login.salesforce.com/services/Soap/u/48.0"/>
</port>
</service>
如果它刚刚生成并留给自己的设备并且没有人想接触 Java...嗯,请检查您是否可以有 2 个已编译的 JAR 文件并排放置,并根据需要将测试或生产版本加载到 Python?
但这似乎真的是一种迂回的做事方式,并且 API v 35 是在大约 3 年前发布的,现在绝对值得检查您的选择。
推荐阅读
- python - docker python apis中是否有docker检查?
- r - 在R中的sapply中将数字转换为罗马数字
- r - 如何从R中的文本字符串数据中提取最重要的动词
- r - 使用 validate+need 或 eventReactive 在 Shiny 中渲染传单不起作用
- python - NumPy 的logical_and.reduce 的内部工作原理
- android - 由于未能安装 SDK 而无法“flutter run”,但 flutter doctor 运行良好
- powershell - Powershell变量分配与管道
- django - Updateview 不仅限于登录用户的 id
- ios - 多层scn文件需要时间来渲染arkit
- javascript - 重命名内置 javascript 函数