I have installed CData ODBC driver for Salesforce and able to connect Salesforce through username, password and security token. I wanted to access through OAuth as well. I have followed all the steps mentioned in the link below. How can we go further.
http://cdn.cdata.com/help/RFE/odbc/pg_oauth.htm
Here is my code to connect Salesforce through username, password and Security Token and able to save the data in a csv file. How to do the same through OAuth?
import pyodbc
import csv
cnxn = pyodbc.connect("DRIVER={CData ODBC Driver for Salesforce};User=yourusername;Password=password;Security Token=security token;")
cursor = cnxn.cursor()
query = "SELECT * from AccountPartner"
cursor.execute(query)
csvfile=open('persons.csv','w', newline='')
obj=csv.writer(csvfile)
for row in cursor:
print(row)
obj.writerow(row)
csvfile.close()
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:
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