2017-11-07 1 views
0

をPostgreSQLのためにパスワードを追加しますトランザクションブロック .Iのドキュメントのすべてのビットを読んで、まだどのよう見当もつかないしています。私が助けることができないならば、私はsqliteに行くでしょう。どのように私は最後まで無視コマンド、私はピーウィーでPostgreSQLサーバに接続したいが、私は、私はパスワードが必要ですが、私は現在のトランザクションが中止され、それを追加する方法を見当もつかないエラーを取得しておくピーウィー

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() 

答えて

0

PostgresqlDatabaseだけpsycopg2.connectに至るまでkwargs追加を渡し、その署名が

conn = psycopg2.connect(dbname="test", user="postgres", password="secret") 

ようなので、あなたは自分のコールにpassword kwarg追加する必要がありますになります。

db = PostgresqlDatabase("Tweets",user='postgres', password='***') 

注意を、ただし、プログラム内のプレーンテキストにデータベースパスワードを格納することは一般的に安全ではありません。私は、トランザクションが終了するまで無視されたコマンドを取得するとき

+0

私はパスワードを追加しています。 – Candocanadian

+0

あなたが得る例外または出力は何ですか? – thaavik

+0

現在のトランザクションは、コマンドはトランザクションブロックの終わりまで無視、中止されます – Candocanadian

関連する問題

 関連する問題