0

I have a very simple python 3.x script that is getting errors when attempting to connect. So far, it simply consists of:

from simple_salesforce import Salesforce
import pandas as pd

sf = Salesforce(instance_url='https://test.salesforce.com', session_id='<provided access token>')

metadata_sf = sf.Contact.describe()

When I do so, I get the error:

SalesforceMalformedRequest: Malformed request https://test.salesforce.com/services/data/v52.0/sobjects/Contact/describe. Response content: [{'errorCode': 'URL_NOT_RESET', 'message': 'Destination URL not reset. The URL returned from login must be set'}]

If I instead use the given URL, like this:

from simple_salesforce import Salesforce
import pandas as pd

sf = Salesforce(instance_url='https://laguna-sobject-4136-dev-ed.scratch.my.salesforce.com', session_id='<provided access token>')

metadata_sf = sf.Contact.describe()

I get the following error:

SalesforceExpiredSession: Expired session for https://laguna-sobject-4136-dev-ed.scratch.my.salesforce.com/services/data/v52.0/sobjects/Contact/describe. Response content: [{'message': 'Session expired or invalid', 'errorCode': 'INVALID_SESSION_ID'}]

I need to find out how to deal with either the 'Malformed request' error, or find out how to refresh or renew the session ID. Any assistance would be appreciated.

Also, I did go into the Domain settings in Salesforce and clicked on 'Check Availability' and it came back with a green checkmark. Finally, the access token was obtained via an automated 'sforg' app generated from Slack. The credentials I received from it were Username, Profile Name, Id, Org Id, Access Token, Instance Url, Login Url, Alias, and Password.

4
  • 1
    The first error is a simple_salesforce bug (why; see here), you should open an issue on their github. The second error has many possible root causes. One possibility: license/permissions. See last couple of paragraphs here
    – identigral
    Nov 29, 2022 at 19:30
  • Thanks @identigral for your response. The second links talks about the need to "obtain a fresh token by repeating the oAuth grant flow". Do you know how I can do this? This is a randomly-generated salesforce instance. Nov 29, 2022 at 20:00
  • Please edit your question and include the steps that show how you obtained the access token.
    – identigral
    Nov 29, 2022 at 20:37
  • done, thank you Nov 29, 2022 at 20:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.