【问题标题】:Python error: sqlite3.OperationalError: no such table: configPython 错误:sqlite3.OperationalError:没有这样的表:配置
【发布时间】:2017-05-16 14:29:24
【问题描述】:

我需要通过命令行将下拉框默认文件夹更改为另一个文件夹,我在互联网上搜索,我找到的所有解决方案都是一样的,使用这个python脚本:

> #!/usr/bin/env  
> # Script for showing or setting the dropbox folder.
> #
> # Execute without options to show current dropbox folder (if non-default).
> # Execute with --setfolder=/foo/bar to set new dropbox folder.
> #
> # I dedicate this work to the public domain by waiving all my rights to the
> # work worldwide under copyright law, including all related and neighboring
> # rights, to the extent allowed by law.
> #
> # You can copy, modify, distribute and perform the work, even for commercial
> # purposes, all without asking permission.
> #
> # Wim Coenen (wcoenen@gmail.com).

import base64
import optparse
import os
import os.path
import sqlite3

# parse command line options
cmdparser = optparse.OptionParser()
cmdparser.add_option("-s","--setfolder", dest="folder",
  help="set dropbox folder")
(options, args) = cmdparser.parse_args()

db_path = os.path.expanduser("~/.dropbox/dropbox.db")
db = sqlite3.connect(db_path)
cursor = db.cursor()

# get dropbox_path
cursor.execute("select value from config where key='dropbox_path'")  
dropbox_path = "<default>"
for entry in cursor:
   dropbox_path_base64 = entry[0]
   dropbox_path_raw = base64.decodestring(dropbox_path_base64)
   dropbox_path = dropbox_path_raw[1:-5]
print "current dropbox path: %s" % dropbox_path

if not options.folder is None:
   new_path_raw = "V" + os.path.abspath(options.folder) + "\np1\n."
   new_path_base64 = base64.encodestring(new_path_raw) 
   cursor.execute("delete from config where key='dropbox_path'")
   cursor.execute("insert into config (key,value) values (?,?)", \
      ("dropbox_path", new_path_base64))
   db.commit()
   print "new dropbox path: %s" % options.folder
   
db.close()

这是我遵循的教程链接:https://whatbox.ca/wiki/Dropbox

所以,我是 python 的新手,当我尝试执行这个脚本时

python ~/Downloads/dropboxdir.py --setfolder=/home/user/new_folder

他返回了这个错误:

cursor.execute("select value from config where key='dropbox_path'")

sqlite3.OperationalError: no such table: config

各位,我需要一盏灯,欢迎任何帮助。

【问题讨论】:

  • 您有一个数据库并在其上运行脚本。并且错误报告数据库内部没有表“config”。我们如何解决这个问题?问题在于缺少所需表的数据库。
  • @aronadaal 嗯,我明白了...那么我可以添加这张表吗?
  • 您可以通过 create table 命令添加表,但 dropbox 似乎已更改
  • @DouglasDiasdaSilva 默认情况下,如果访问路径中不存在 sqlite3 数据库,则 sqlite3 库将创建一个空白数据库。很可能这是您查看错误“表不存在”的原因。我建议检查DB是否存在,如果存在,请使用浏览sqlite3数据库的chrome扩展并在通过程序访问之前手动检查DB的内容。
  • @VijayakumarUdupa 嗯...有趣,那么我如何检查 DB 是否完全存在?我从不使用 sqlite3...

标签: python ubuntu dropbox


【解决方案1】:

数据库是非开源软件的内部部分。我会假设 Dropbox 的开发人员已经改变了数据库的结构。

在我在 OSX 上使用 Dropbox 版本 v16.4.30 的情况下,dropbox.db 文件甚至不存在,因此他们对其进行了更多更改

【讨论】:

  • 你是说sqlite3的开发者?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多