目标是使用jupyter notebook操作存储在google drive中的SQLite数据库。我找到了一种使用谷歌协作来访问google drive中的SQLite数据库的方法,但我不知道在jupyter notebook中怎么做。
使用以下代码,我可以访问google drive,但无法连接到SQLite数据库。
如何修改"conn = sqlite3.connect(drive_path + db_name)“部分的代码?
如果你能让我知道,我将不胜感激。
#####################
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
drive = GoogleDrive(gauth)
import sqlite3
drive_path = "/My Drive/database/"
db_name = "test.db"
conn = sqlite3.connect(drive_path + db_name)
cur = conn.cursor()发布于 2021-10-10 06:34:58
不知道我的解决方案是否适用于您。您可能已经知道,由于Sqlite仅基于文件,因此数据库文件必须位于网络共享文件夹中。在我的Mac上,我将Google驱动器挂载为本地驱动器中的文件夹,然后以常规本地文件的形式访问google驱动器数据库文件:
conn = sqlite3.connect('/Users/local/Google Drive (xxxx@gmail.com)/sample.db')https://stackoverflow.com/questions/67887262
复制相似问题