我试图建立的应用程序,得到保存的用户时间轴上的推文在烧瓶。但是出现了这个错误。 这个程序在我的本地服务器/环境中运行,但是当我在Heroku上托管它时,它就崩溃了。 app / init . py
# Initialized app
app = Flask(__name__, instance_relative_config=True)
configure_app(app)
# Initialized database
db = SQLAlchemy(app)
migrate = Migrate(app, db)
db.init_app(app)
# Get timeline tweet
import main.get_tweet
app / get_tweet.py
from flask import current_app
from requests_oauthlib import OAuth1Session
from apscheduler.schedulers.background import BackgroundScheduler
from main.database import save_tweet
import tweepy
def get_current_tweet():
client_id = current_app.config['TWITTER_CLIENT_ID']
client_secret = current_app.config['TWITTER_CLIENT_SECRET']
base_url = 'https://api.twitter.com/'
user_timeline_url = base_url + 'statuses/user_timeline'
users = fetch_users()
for user in users:
try:
twitter_profile = user.twitter_profile_info()
oauth_token = twitter_profile.access_token
oauth_verifier = twitter_profile.access_secret
auth = tweepy.OAuthHandler(client_id, client_secret)
auth.set_access_token(oauth_token, oauth_verifier)
api = tweepy.API(auth)
user_tweets=api.user_timeline(screen_name=twitter_profile.screen_name, count=1, exclude_replies=False, include_rts=False)
status = user_tweets[0]._json
save_tweet(status, user)
except:
print(user.name + " has been errored.")
sched = BackgroundScheduler(standalone=True,coalesce=True)
sched.add_job(get_current_tweet, 'interval', minutes=10)
sched.start()
app / database.py
def update_or_create_current_tweet(request, user):
twitter_profile = user.twitter_profile_info()
uid = request['id']
url = "https://twitter.com/" + twitter_profile.screen_name + "/status/" + str(uid)
content = request['text']
tweet = Tweet(
uid=uid,
user_id=user.id,
url=url,
content=content
)
db.session.add(tweet)
db.session.commit()
return current_tweet
问题来源StackOverflow 地址:/questions/59385821/heroku-postgres-python-too-many-connections-error
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。