简体   繁体   English

无法通过 python API 登录到 Salesforce Sandbox

[英]Cannot login to Salesforce Sandbox via python API

I am using the python3.7.2 module simple-salesforce==0.74.2 and I am having trouble trying to establish a connection to my salesforce sandbox.我正在使用 python3.7.2 模块simple-salesforce==0.74.2 ,我在尝试建立与我的 salesforce 沙箱的连接时遇到了问题。 I can login to the salesforce production with the same credentials just fine like so:我可以像这样使用相同的凭据登录到 salesforce production:

from simple_salesforce import Salesforce
sf = Salesforce(username='user@domain.com', password='pswd', security_token='mytoken')

Okay cool.好的,很酷。 Now I attempt to login to my sandbox with the following:现在我尝试使用以下内容登录我的沙箱:

sf = Salesforce(username='user@domain.com.sandbox_name', password='pswd', security_token='mytoken', sandbox=True)

And I get the error:我得到了错误:

simple_salesforce.exceptions.SalesforceAuthenticationFailed: INVALID_LOGIN: Invalid username, password, security token; simple_salesforce.exceptions.SalesforceAuthenticationFailed:INVALID_LOGIN:无效的用户名、密码、安全令牌; or user locked out.或用户被锁定。

So I tried logging in with a different method:所以我尝试使用不同的方法登录:

sf = Salesforce(username='user@domain.com.sandbox_name', password='pswd', security_token='mytoken', domain='sandbox_name')

And this gave a different error:这给出了一个不同的错误:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='sandbox_name.salesforce.com', port=443): Max retries exceeded with url: /services/Soap/u/38.0 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known')) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='sandbox_name.salesforce.com', port=443): 最大重试次数超过 url: /services/Soap/u/38.0 (由 NewConnectionError(': 建立新连接失败引起: [Errno 8] 提供了节点名或服务名,或未知'))

I am using a Developer sandbox, named sandbox_name , following salesforce's instructions.我正在按照 salesforce 的说明使用名为sandbox_name的开发人员沙箱。 Can someone give some advice on what I am doing incorrectly?有人可以就我做错了什么提出一些建议吗?

Solved.解决了。 Set domain='test' and generate a new token under your sandbox account设置domain='test'并在您的沙箱帐户下生成一个新令牌

this didn't work for me, but what did was:这对我没用,但有用的是:

`sf = Salesforce(
    username='my.email@test.com', 
    password='sadfd8d8d8', 
    security_token='d8d8asd8f8d8',
    instance_url='https://my-dev-org-instance-dev-ed.my.salesforce.com')`

The advice here may be a bit deprecated.这里的建议可能有点过时了。 After a bit of tinkering, I was able to get the simple_salesforce library working with the Salesforce sandbox on a custom domain with the following code.经过一些修补后,我能够使用以下代码在自定义域上使用 simple_salesforce 库与 Salesforce 沙箱一起工作。 Note the domain that I am passing to the api as well the sand_box name that needs to be appended to the username.请注意我传递给 api 的域以及需要附加到用户名的 sand_box 名称。

from simple_salesforce import Salesforce

USER = "user@domain.com.sandbox_name"
PASS = "pass"
SEC_TOKEN = "token"
DOMAIN = "<domain>--<sandbox_name>.<instance>.my"

sf = Salesforce(username=USER, password=PASS, security_token=SEC_TOKEN, domain=DOMAIN)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM