- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我不是根用户的服务器中使用 psycopg2 填充几个数据库(不知道它是否相关)。我的代码看起来像
import json
from psycopg2 import connect
cors = connect(user='jungal01', dbname='course')
req = connect(user="jungal01", dbname='requirement')
core = cors.cursor()
reqs = req.cursor()
with open('gened.json') as gens:
geneds = json.load(gens)
for i in range(len(geneds)):
core.execute('''insert into course (number, description, title)
values({0}, {1}, {2});''' .format(geneds[i]["number"], geneds[i]['description'], geneds[i]['title'] ))
reqs.execute('''insert into requirement (fulfills)
values({0});''' .format(geneds[i]['fulfills'] ))
db.commit()
当我执行代码时,出现上述 pycopg2 错误。我知道存在这些特定的数据库,但我就是不明白为什么它无法连接到我的数据库。 (附带任务,我也不确定该提交语句。它应该在 for 循环中还是在循环之外?它应该是特定于数据库的?)
最佳答案
首先,您的 db
不是已定义的变量,因此无论如何您的代码都不应该完全运行。
\list on this server is a bunch of databases full of usernames, of which my username is one
那么下面是你应该如何连接。对于数据库,而不是表,常规模式是输入数据库名称,然后是用户/密码。
“模式”在关系数据库中是一个松散的术语。表和数据库都有模式,但您似乎期望连接到表,而不是数据库。
因此,请尝试使用此代码来修复缩进和 SQL 注入(inject)问题 -- See this documentation
请注意,您首先必须在要连接的数据库中创建两个表。
import json
from psycopg2 import connect
username = 'jungal01'
conn = connect(dbname=username, user=username)
cur = conn.cursor()
with open('gened.json') as gens:
geneds = json.load(gens)
for g in geneds:
cur.execute('''insert into course (number, description, title)
values(%(number)s, %(description)s, %(title)s);''', g)
cur.execute('''insert into requirement (fulfills)
values(%(fulfills)s);''', g)
conn.commit()
关于python - psycopg2.OperationalError : FATAL: database does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600140/
我有一个 Pandas 数据框,如下所示。 activity User_Id \ 0 VIEWED MOVIE 158d292ec18a49 1 VIEWED
我正在尝试在运行 12.04 的 Ubuntu 机器上使用 mysql 创建一个远程数据库。 它有一个启用了远程登录的根用户。我已经启动了服务器。 输出 sudo netstat -tap | gre
这个问题在这里已经有了答案: sqlalchemy.exc.OperationalError: (OperationalError) unable to open database file Non
我正在尝试使用 SQLAlchemy(使用 Flask)创建模型,但我无法在互联网上的任何地方找到解决我的问题的方法。 它给我的错误是 sqlalchemy.exc.OperationalError:
我收到以下错误: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: s_amodel [SQL: '
我搜索了很多这个错误,但我只找到了一些背后有更多信息的信息,比如“FATAL: ...”。我的没有。它只是说 sqlalchemy.exc.OperationalError: (psycopg2.Op
我在使用 flask_alchemy 进行单元测试时遇到问题 生产环境我用的是postgresql数据库 "SQLALCHEMY_DATABASE_URI": "postgresql://login:
运行.py文件: from flaskblog import app, db if __name__ == '__main__': db.create_all() app.run(de
我已在本地成功运行我的 Flask 应用程序,但是当我将其部署到我的产品环境时,出现此错误: [2019-08-26 00:15:36,229] ERROR in app: Exception on
服务 我的服务基于flask + postgresql + gunicorn + supervisor + nginx docker部署的时候,运行服务后,再访问api,有时候会报错,有时候还可以。
我定义了表名 users_table 并运行 db.create_all() 来创建表,但是在提交更新用户信息时出现错误“no such table user_table”。 我如何测试: (unde
我目前正在第一次编写一些 Airflow DAG 完整性测试。我遇到了一个错误,我的一些运算符(operator)/任务引用了 Airflow 变量,例如: test_var= Variable.ge
我正在尝试通过 flask 中的 sqlalchemy 执行原始 sql 查询。在 psql 中运行时,原始 sql 查询会给出正确的输出。 postgres=# SELECT distin
import requests import time import csv import ast import sys import mysql.connector config = { 'user
我用了很长时间的Postgres 14和PGAdmin4 6.7,一切都很好。这是在Windows11上。昨天我试着升级到Postgres 15和PGAdmin4 7.6,但这就是它失败的地方!。Po
错误: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: password authentication fai
我正在使用 Python、Flask 和 SQLAlchemy。我在构建应用程序时一直使用本地数据库,并且它在以下代码中运行良好: from flask import Flask from flask
我正在尝试使用 mysql 来运行 python-flask Web 应用程序。但是,我在主应用程序文件中连接到数据库,每次尝试将数据输入数据库(即注册客户)时,我都会收到错误消息: Tracebac
我想从当前数据库切换到另一个 MySQL 数据库(从后台)。所以,我想这与我设置数据库设置的方式有关。 engine = create_engine('mysql+mysqldb://user:pw@
我在 Google AppEngine 上使用带有 Flask 的应用程序,我使用此常量 SQLALCHEMY_DATABASE_URI = 'mysql://user:pass@ip_address
我是一名优秀的程序员,十分优秀!