SQLクエリを実行するpythonスクリプトを持っています&はSQLite3データベースファイルから情報を取得します。 SQLite3データベースファイルは、実行中のスクリプトとは異なるディレクトリにあります。これらはすべて、cgi-binディレクトリ内のWebホスト(Unixサーバのcpanel)で発生します。Linux/Unix Server:スクリプトを実行するディレクトリとは異なるディレクトリにあるSQLデータベース
私の質問/問題: pythonスクリプトを別のディレクトリにあるSQLite3データベースにアクセス/接続することは可能ですか?今は私のウェブホスト上でスクリプトを実行すると、SQLite3データベースに接続できません。
私のpythonファイルは、このディレクトリのwebhost:public_HTML/cgi-bin/dataMiner /にあります。 SQLite3データベースファイルは、このディレクトリのpublic_HTML/cgi-bin /にあります。
Pythonスクリプトでの私のコードは次のとおりです。
import DataMiner
def connect_ex(f_name):
""" Post: """
try:
# When the script runs the file is never found but it actually does exist
if not os.path.isfile(f_name):
raise Exception("")
conn = sqlite3.connect(f_name)
return conn
except IOError, msg:
#print str(msg)
return None
except OSError, msg:
#print str(msg)
return None
except sqlite3.OperationalError, msg:
#print str(msg)
return None
except Exception, e:
return None
conn = connect_ex("../competitionDB.db")
res = DataMiner.execute_query(conn, "SELECT * FROM MyTable;")
print res
conn.close()
「相対パス」の代わりにdbの「絶対パス」を入れてみましたか? – mwan
あなたは次のようになります:http://mywebsite/cgi-bin/compDb.db?その後、はいと同じ問題が発生します – Mitch
あなたはどのようなエラーメッセージが表示されますか?権限の問題である可能性がありますか? IEはWebサーバーのユーザー(多くのホスト上のユーザー名とは異なります)は、DBとそのディレクトリにアクセスできますか? – intuited