The instructions you need are further down in the documentation (also copied below): http://cdn.cdata.com/help/RFE/odbc/pg_oauthcustomappcreate.htm
You'll need to create the custom app in Salesforce and then set the prescribed OAuth-related connection properties in your connection string. Your code to create the connection will look like the following:
cnxn = pyodbc.connect("DRIVER={CData ODBC Driver for Salesforce};OAuthClientID=MY_CONSUMER_KEY;OAuthClientSecret=MY_CONSUMER_SECRET;OAuthCallbackURL=https://localhost:33333;InitiateOAuth=GETANDREFRESH;")
You may need to test the connection and trigger the OAuth flow outside of Python first. The instructions for that process can be found in the Unix ODBC section of the Help (http://cdn.cdata.com/help/RFE/odbc/pg_unixODBConlinux.htm) but are also copied below.
Instructions Copied from Documentation
Create a Connected App
To obtain the OAuth client credentials, consumer key, and consumer
secret:
- Log in to Salesforce.com.
- From Setup, enter Apps in the Quick Find box and then click the link to create an app.
- In the Connected Apps section of the resulting page, click New. Enter a name to be displayed to users when they log in to grant permissions to your app, along with a contact Email address.
- Click Enable OAuth Settings and enter a value in the Callback URL box. If you are making a desktop application, set the Callback URL to http://localhost:33333 or a different port number of your choice. If you are making a web application, set the Callback URL to a page on your Web app you want the user to be returned to after they have authorized your application.
- Select the scope of permissions that your app should request from the user.
- Click your app name to open a page with information about your app. The OAuth client credentials, the consumer key, and consumer secret are displayed.
Authenticate to Salesforce from a Desktop Application
After setting the following connection properties, you are ready to connect:
- OAuthClientId: Set to the consumer key in your app settings.
- OAuthClientSecret: Set to the consumer secret in your app settings.
- CallbackURL: Set to the callback URL in your app settings.
- InitiateOAuth: Set to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken connection property.
When you connect, the driver opens the OAuth endpoint in your default browser. Log in and grant permissions to the application. The driver then completes the following OAuth process:
- Gets the callback URL and sets the access token and OAuthServerUrl to authenticate requests.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
- Exchanges the returned refresh token for a new, valid access token.
Using unixODBC
Define a DSN
Create a DSN by adding an entry to odbc.ini
or .odbc.ini
. Below is an example DSN entry:
[CData Salesforce Source]
Driver=/opt/cdata/cdata-odbc-driver-for-salesforce/lib/libsalesforceodbc.x64.so
OAuthClientID=MY_CONSUMER_KEY
OAuthClientSecret=MY_CONSUMER_SECRET
OAuthCallbackURL=https://localhost:33333
InitiateOAuth=GETANDREFRESH
Test the Connection
You can use the unixODBC test tool, isql, to execute SQL queries to Salesforce from the command line. When testing the connection, use the -v flag to output any messages from the driver manager and the driver.
isql -v "CData Salesforce Source"