betodealmeida / gsheets-db-api

A Python DB-API and SQLAlchemy dialect to Google Spreasheets
MIT License
213 stars 16 forks source link

Getting error: "Connection failed" #8

Open hemantaggarwal opened 4 years ago

hemantaggarwal commented 4 years ago

I installed gsheetsdb package and tried to use it in superset and in python script but I am getting connection failed error. What should be the full uri for gsheets?

Kindly help in this issue.

JagritiG commented 3 years ago

I have Installed package 'gsheetsdb' (version=0.1.12) and other dependencies from the requirement.txt file. Then, I have run the following code in PyCharm:

from sqlalchemy import *
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import *

# Connection and authentication
service_account_file = "service_account_file.json"    # your service account credential file
engine = create_engine('gsheets://', service_account_file=service_account_file, subject='your_business_domain@xx.com')
inspector = inspect(engine)
url = "google_spread_sheet_url"

# Processing
table = Table(
    url,
    MetaData(bind=engine),
    autoload=True)

query = select([func.count(table.columns.cnt)], from_obj=table)
print(query.scalar())

Note: This works for me. You can try using a python script.

hemantaggarwal commented 3 years ago

Thanks @JagritiG for the comment. I have started using a different approach but this will be helpful in future.