Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I can login to the salesforce production with the same credentials just fine like so:

from simple_salesforce import Salesforce
sf = Salesforce(username='[email protected]', password='pswd', security_token='mytoken')

Okay cool. Now I attempt to login to my sandbox with the following:

sf = Salesforce(username='[email protected]_name', password='pswd', security_token='mytoken', sandbox=True)

And I get the error:

simple_salesforce.exceptions.SalesforceAuthenticationFailed: INVALID_LOGIN: Invalid username, password, security token; or user locked out.

So I tried logging in with a different method:

sf = Salesforce(username='[email protected]_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'))

I am using a Developer sandbox, named sandbox_name, following salesforce's instructions. Can someone give some advice on what I am doing incorrectly?

like image 619
lollerskates Avatar asked Sep 19 '25 21:09

lollerskates


2 Answers

Solved. Set domain='test' and generate a new token under your sandbox account

like image 65
lollerskates Avatar answered Sep 23 '25 10:09

lollerskates


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. Note the domain that I am passing to the api as well the sand_box name that needs to be appended to the username.

from simple_salesforce import Salesforce

USER = "[email protected]_name"
PASS = "pass"
SEC_TOKEN = "token"
DOMAIN = "<domain>--<sandbox_name>.<instance>.my"

sf = Salesforce(username=USER, password=PASS, security_token=SEC_TOKEN, domain=DOMAIN)
like image 21
HarshMarshmallow Avatar answered Sep 23 '25 12:09

HarshMarshmallow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!