#๐Ÿ”’ "could not translate hostname 'hostname' to address: Name or service not known."

4 messages ยท Page 1 of 1 (latest)

rustic marlin
#

So basically, I'm trying to connect to a PostgreSQL database on Render with my website. The problem I'm encountering is that it works locally, but during deployment, I get this error: "could not translate hostname 'hostname' to address: Name or service not known." I've double-checked everything, and the data seems correct, but I can't find a solution to this problem. Also i get this (Background on this error at: https://sqlalche.me/e/20/e3q8) but I read the docs and nothing seems to help. Here is the code:

from flask import Flask, render_template, redirect, url_for, flash,request,jsonify,session,get_flashed_messages
from flask_login import UserMixin, LoginManager
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
from wtforms import SelectMultipleField, SubmitField
from wtforms.validators import DataRequired,Email
from wtforms import TextAreaField,StringField
from wtforms.validators import ValidationError
from flask_migrate import Migrate
from dotenv import load_dotenv
import os
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, Column, String, Integer, DateTime


engine = create_engine(f'EXTERNAL DATABASE URL')
Session = sessionmaker(bind=engine)



app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("SQLALCHEMY_DATABASE_URI")

app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY')
db = SQLAlchemy(app)
login_manager = LoginManager(app)


@login_manager.user_loader
def load_user(user_id):
    return Users.query.get_or_404(user_id)


class Users(db.Model, UserMixin):
    __tablename__ = "website_basic"
    id = db.Column(db.Integer, primary_key=True)
    .
    .
    .
    .


with app.app_context():
    db.create_all()

.
.
.
.
.

if __name__ == "__main__":
    app.run(debug=True)
hidden steppeBOT
#

@rustic marlin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hidden steppeBOT
#

@rustic marlin

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.