I am writing a Python script to insert data, and got following error.

I am using Sandbox now.

Traceback (most recent call last):
File "/home/jdoe/Desktop/John/SurveyProjectDataIntegration/SurveySelectionDataInsert_v3.py", line 19, in <module>
from SfSimpleSf2 import *
File "/home/jdoe/Desktop/John/SurveyProjectDataIntegration/SfSimpleSf2.py", line 5, in <module>
sf = Salesforce(username=curUser, password=curPass, security_token=curToken)
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/api.py", line 74, in __init__
File "/usr/local/lib/python2.7/dist-packages/simple_salesforce/login.py", line 124, in SalesforceLogin
code=except_code, message=except_msg))
simple_salesforce.login.SalesforceAuthenticationFailed: INVALID_LOGIN: Invalid username, password, security token; or user locked out.

When I checked the Login History at Sandbox's Org --> My Settings --> Personal --> Login History, it does not even show that it attempted logging in.

I double-checked the credentials (login, pwd and securitytoken) at crendential page, they all look fine.

Is there any other areas that need to be considered?

  • 3
    Did you make sure you're logging in to test.salesforce.com instead of login.salesforce.com?
    – sfdcfox
    Jul 5, 2017 at 20:10
  • Yes. I did checked, and it is pointing to credential of test.salesforce.com.
    – Java
    Jul 5, 2017 at 20:28
  • 1
    If the URL is correct, the user name is not correct. Make sure you are using your sandbox user name, and not your production user name.
    – sfdcfox
    Jul 5, 2017 at 20:32
  • @sfdcfox I realized that my Python files are working on Production org. So the issue has to do with some configuration settings for Sandbox environment. Thanks!
    – Java
    Jul 5, 2017 at 21:14
  • No problem! It happens to the best of us. I'm glad you got it resolved.
    – sfdcfox
    Jul 5, 2017 at 21:14

1 Answer 1


When using Simple Salesforce and logging into your sandbox it is important you set sandbox equals to True when authenticating. This doesn't appear to be the case based on the error message you posted:

File "/home/jdoe/Desktop/John/SurveyProjectDataIntegration/SfSimpleSf2.py", line 5, in sf = Salesforce(username=curUser, password=curPass, security_token=curToken)

You would need to authenticate with the sandbox parameter set to true as follows:

sf = Salesforce(username=curUser, 

as pointed out in the documentation.

  • seems like this is now: domain='test'
    – influent
    Dec 7, 2023 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .