[英]How do I add password to postgresql peewee
我想用peewee连接到PostgreSQL服务器,但是我一直收到一个错误,我需要密码,但是我不知道如何添加它,当前事务已中止,命令被忽略,直到事务块结束。我已经阅读了文档,仍然不知道如何。 如果我不能帮我,我就去sqlite。
from twython import Twython, TwythonError
import json
from peewee import *
"""Setting up variables"""
db = PostgresqlDatabase("Tweets",user='postgres')
Cred_Filename = 'Keys.json'
jf = open(Cred_Filename)
creds = json.load(jf)
jf.close()
twitter = Twython(creds['consumer_key'],
creds['consumer_secret'],
creds['access_token'],
creds['access_token_secret'])
"""End of variables"""
"""PostgreSql Setup"""
class BaseModel(Model):
"""A base model that will use our Postgresql database"""
class Meta:
database = db
class Tweet(BaseModel):
tweet = CharField()
try:
Tweet.create_table()
except Exception as e:
pass
"""End of PostgreSql Setup"""
"""Pulling Tweets and displaying them"""
def PullTweet():
"""Take user input and pull and print 10 newest tweets"""
user_input = input('Please Enter A Username: ')
try:
user_timeline = twitter.get_user_timeline(screen_name=user_input)
except TwythonError as e:
print(e)
print(user_input)
for tweets in user_timeline:
print('[*]' + tweets['text'])
try:
tweet = Tweet(tweet=tweets['text'])
tweet.save()
except Exception as e:
print(e)
PullTweet()
PostgresqlDatabase
只是将其他kwargs
传递给psycopg2.connect
,该签名看起来像
conn = psycopg2.connect(dbname="test", user="postgres", password="secret")
因此,您只需要在呼叫中添加password
kwarg:
db = PostgresqlDatabase("Tweets",user='postgres', password='***')
但是请注意,在程序中以纯文本格式存储数据库密码通常并不安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.