Heroku error: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused - postgresql

app.py:
from flask import Flask ,render_template,request,url_for,redirect
from flask_sqlalchemy import SQLAlchemy
import psycopg2
app=Flask(__name__)
app.debug=False
app.config['SQLALCHEMY_DATABASE_URI']='postgres://myherokupostgresdatabasepassword'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=False
db=SQLAlchemy(app)
class Username(db.Model):
__tablename__ = "username"
id=db.Column(db.Integer,primary_key=True)
username=db.Column(db.String(200),unique=True)
def __init__(self,username):
self.username=username
#app.route("/submit",methods=["POST"])
def submit():
if request.method=="POST":
usernamee=request.form["username"]
usernamee=usernamee.replace(" ","")
sayi=db.session.query(Username).filter(Username.username==usernamee).count()
print("has been created-------------------->>",sayi,"times")
if usernamee=="" or usernamee==" ":
return "input is empty .please enter real username."
if sayi>0:
return "{} didnt created .because there is username like this alreay.".format(usernamee)
register=Username(username=usernamee)
db.session.add(register)
db.session.commit()
return render_template("submit.html",message="{} have been entered".format(usernamee))
return render_template("submit.html")
#app.route("/",)
def index():
all=db.session.query(Username).all()
return render_template("register.html",usernames=all)
if __name__=="__main__":
app.debug=True
app.run()
error:*
2020-04-19T18:51:16.120751+00:00 app[web.1]: File
"/app/.heroku/python/lib/python3.7/site-packages/psycopg2/init.py",
line 127, in connect 2020-04-19T18:51:16.120751+00:00 app[web.1]:
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2020-04-19T18:51:16.120752+00:00 app[web.1]:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not
connect to server: Connection refused 2020-04-19T18:51:16.120752+00:00
app[web.1]: Is the server running on host "localhost" (127.0.0.1) and
accepting 2020-04-19T18:51:16.120752+00:00 app[web.1]: TCP/IP
connections on port 5432?
*
when i run this command
>> from app import db
>> db.create_all()
it gives me this error:
Traceback (most recent call last): File
"/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2285, in _wrap_pool_connect
return fn() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 363, in connect
return _ConnectionFairy._checkout(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 773, in _checkout
fairy = _ConnectionRecord.checkout(pool) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 492, in checkout
rec = pool._do_get() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/impl.py",
line 139, in _do_get
self._dec_overflow() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py",
line 69, in exit
exc_value, with_traceback=exc_tb, File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/compat.py",
line 178, in raise_
raise exception File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/impl.py",
line 136, in _do_get
return self._create_connection() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 308, in _create_connection
return _ConnectionRecord(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 437, in init
self.connect(first_connect_check=True) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 657, in __connect
pool.logger.debug("Error on connect(): %s", e) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py",
line 69, in __exit
exc_value, with_traceback=exc_tb, File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/compat.py",
line 178, in raise_
raise exception File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 652, in connect
connection = pool._invoke_creator(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py",
line 114, in connect
return dialect.connect(*cargs, **cparams) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/default.py",
line 490, in connect
return self.dbapi.connect(*cargs, **cparams) File "/app/.heroku/python/lib/python3.7/site-packages/psycopg2/__init.py",
line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "", line 1, in
File
"/app/.heroku/python/lib/python3.7/site-packages/flask_sqlalchemy/init.py",
line 1033, in create_all
self._execute_for_all_tables(app, bind, 'create_all') File "/app/.heroku/python/lib/python3.7/site-packages/flask_sqlalchemy/init.py",
line 1025, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/sql/schema.py",
line 4321, in create_all
ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables File
"/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2057, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn: File "/app/.heroku/python/lib/python3.7/contextlib.py", line 112, in
enter
return next(self.gen) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2049, in _optional_conn_ctx_manager
with self._contextual_connect() as conn: File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2251, in _contextual_connect
self._wrap_pool_connect(self.pool.connect, None), File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2289, in _wrap_pool_connect
e, dialect, self File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 1555, in _handle_dbapi_exception_noconnection
sqlalchemy_exception, with_traceback=exc_info[2], from_=e File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/compat.py",
line 178, in raise_
raise exception File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/base.py",
line 2285, in _wrap_pool_connect
return fn() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 363, in connect
return _ConnectionFairy._checkout(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 773, in _checkout
fairy = _ConnectionRecord.checkout(pool) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 492, in checkout
rec = pool._do_get() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/impl.py",
line 139, in _do_get
self._dec_overflow() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py",
line 69, in exit
exc_value, with_traceback=exc_tb, File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/compat.py",
line 178, in raise_
raise exception File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/impl.py",
line 136, in _do_get
return self._create_connection() File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 308, in _create_connection
return _ConnectionRecord(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 437, in init
self.connect(first_connect_check=True) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 657, in __connect
pool.logger.debug("Error on connect(): %s", e) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py",
line 69, in __exit
exc_value, with_traceback=exc_tb, File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/util/compat.py",
line 178, in raise_
raise exception File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/pool/base.py",
line 652, in connect
connection = pool._invoke_creator(self) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py",
line 114, in connect
return dialect.connect(*cargs, **cparams) File "/app/.heroku/python/lib/python3.7/site-packages/sqlalchemy/engine/default.py",
line 490, in connect
return self.dbapi.connect(*cargs, **cparams) File "/app/.heroku/python/lib/python3.7/site-packages/psycopg2/__init.py",
line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection
refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
(Background on this error at: http://sqlalche.me/e/e3q8)
>

Related

when i run yolo_v1, raise my connection error

I refer https://github.com/ssaru/You_Only_Look_Once
when I run main.py, raising my connection error.
Looks like a connection error, but I don't know what the code is trying to connect to.
How can I solve this?
Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw) File "/usr/local/lib/python3.7/dist-packages/urllib3/util/connection.py", line 80, in create_connection
raise err File "/usr/local/lib/python3.7/dist-packages/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked) File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.7/http/client.py", line 1281, in request
self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1327, in _send_request
self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1276, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.7/http/client.py", line 1036, in _send_output
self.send(msg) File "/usr/lib/python3.7/http/client.py", line 976, in send
self.connect() File "/usr/local/lib/python3.7/dist-packages/urllib3/connection.py", line 181, in connect
conn = self._new_conn() File "/usr/local/lib/python3.7/dist-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e) urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f5e0a35a5d0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/requests/adapters.py", line 449, in send
timeout=timeout File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.7/dist-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /update (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5e0a35a5d0>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/visdom/__init__.py", line 711, in _send
data=json.dumps(msg), File "/usr/local/lib/python3.7/dist-packages/visdom/__init__.py", line 677, in _handle_post
r = self.session.post(url, data=data) File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 578, in post
return self.request('POST', url, data=data, json=json, **kwargs) File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.7/dist-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /update (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5e0a35a5d0>: Failed to establish a new connection: [Errno 111] Connection refused')) Exception in user code:

PyTorch Net.train() fails to establish connection - what for?

I am trying to train a neural network in PyTorch following a git tutorial. When it comes to train the network I get a row of exceptions linked to a failed connection attempt (probably with some google server):
Traceback (most recent call last):
File "/home/***/.local/lib/python3.6/site-packages/urllib3/connection.py", line 157, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/***/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 61, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/home/***/.conda/envs/cv-nd/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/***/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/***/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/***/.conda/envs/cv-nd/lib/python3.6/http/client.py", line 1262, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/***/.conda/envs/cv-nd/lib/python3.6/http/client.py", line 1308, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/***/.conda/envs/cv-nd/lib/python3.6/http/client.py", line 1257, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/***/.conda/envs/cv-nd/lib/python3.6/http/client.py", line 1036, in _send_output
self.send(msg)
File "/home/*.*/.conda/envs/cv-nd/lib/python3.6/http/client.py", line 974, in send
self.connect()
File "/home/*.*/.local/lib/python3.6/site-packages/urllib3/connection.py", line 184, in connect
conn = self._new_conn()
File "/home/*.*/.local/lib/python3.6/site-packages/urllib3/connection.py", line 169, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7ff4d4cc87f0>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/*.*/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/*.*/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/*.*/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='metadata.google.internal', port=80): Max retries exceeded with url: /computeMetadata/v1/instance/attributes/keep_alive_token (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff4d4cc87f0>: Failed to establish a new connection: [Errno -2] Name or service not known',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "NB2.py", line 229, in <module>
with active_session():
File "/home/*.*/.conda/envs/cv-nd/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/home/*.*/Code/faceNNtrain/Facial_Keypoint_Detection/workspace_utils.py", line 31, in active_session
token = requests.request("GET", TOKEN_URL, headers=TOKEN_HEADERS).text
File "/home/*.*/.local/lib/python3.6/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/*.*/.local/lib/python3.6/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/home/*.*/.local/lib/python3.6/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/home/*.*/.local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='metadata.google.internal', port=80): Max retries exceeded with url: /computeMetadata/v1/instance/attributes/keep_alive_token (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff4d4cc87f0>: Failed to establish a new connection: [Errno -2] Name or service not known',))
I am confused since there is no external call required, and it is nowhere defined in my code (including model definition) - it probably sits somewhere hidden in the libraries, but still, it fails, messes everything up and idk how to fix it. I checked my local firewall and all, but the only host from the errors I could check (metadata.google.internal) is also not reachable from other clients. Any ideas?

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied

i am trying to run this simple flask app and I keep getting this error in the terminal when trying to run the flask app
FLASK_APP=app.py flask run
i keep getting this error :
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied
here is my app:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres#localhost:5432/testdb'
db = SQLAlchemy(app)
class Person(db.Model):
__tablename__ = 'persons'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(), nullable=False)
db.create_all()
#app.route('/')
def index():
return 'Hello World!'
just to clarify i have psycopg2, flask-SQLAlchemy and all dependencies installed AND THERE IS NO PASSWORD FOR USER postgres by default and i haven't changed that and i can log in to database as postgres using psql without password without any problems.
Full error output:
FLASK_APP=app.py flask run
* Serving Flask app "app.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.
warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.')
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1122, in _do_get
return self._pool.get(wait, self._timeout)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/queue.py", line 145, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
return fn()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 387, in connect
return _ConnectionFairy._checkout(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 516, in checkout
rec = pool._do_get()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
self._dec_overflow()
File "/usr/lib/python3/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
return self._create_connection()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
return _ConnectionRecord(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 461, in __init__
self.__connect(first_connect_check=True)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 651, in __connect
connection = pool._invoke_creator(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 393, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/aa/.local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/aa/.local/bin/flask", line 11, in <module>
sys.exit(main())
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 848, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 305, in __init__
self._load_unlocked()
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 330, in _load_unlocked
self._app = rv = self.loader()
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 388, in load_app
app = locate_app(self, import_name, name)
File "/home/aa/.local/lib/python3.6/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/aa/Desktop/Udacity - FullStackND 2020/FullStackND2020/Practice Projects/flask hello world app/app.py", line 18, in <module>
db.create_all()
File "/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py", line 972, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/lib/python3/dist-packages/flask_sqlalchemy/__init__.py", line 964, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/usr/lib/python3/dist-packages/sqlalchemy/sql/schema.py", line 3934, in create_all
tables=tables)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1928, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1921, in _optional_conn_ctx_manager
with self.contextual_connect() as conn:
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2112, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2151, in _wrap_pool_connect
e, dialect, self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 1465, in _handle_dbapi_exception_noconnection
exc_info
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
return fn()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 387, in connect
return _ConnectionFairy._checkout(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 766, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 516, in checkout
rec = pool._do_get()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1138, in _do_get
self._dec_overflow()
File "/usr/lib/python3/dist-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/usr/lib/python3/dist-packages/sqlalchemy/util/compat.py", line 187, in reraise
raise value
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 1135, in _do_get
return self._create_connection()
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 333, in _create_connection
return _ConnectionRecord(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 461, in __init__
self.__connect(first_connect_check=True)
File "/usr/lib/python3/dist-packages/sqlalchemy/pool.py", line 651, in __connect
connection = pool._invoke_creator(self)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/strategies.py", line 105, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/lib/python3/dist-packages/sqlalchemy/engine/default.py", line 393, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/home/aa/.local/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) fe_sendauth: no password supplied
Other than just setting a password, you can log in without a password by:
Enable trust authentication, eg echo "local all all trust" | sudo tee -a /etc/postgresql/10/main/pg_hba.conf
Create a role with login access with the same username as your local username, eg if whoami returns myname, then sudo -u postgres psql -c "CREATE ROLE myname WITH LOGIN"
Use sqlalchemy's postgresql unix domain connection instead of tcp (ref), eg "postgres+psycopg2://myname#/mydb"
Note that this requires installing pip3 install psycopg2-binary
so apparently you need a password to connect to database from SQLAlchemy, I was able to work around this by simply creating a password or adding new user with password.
let me know if there is a different work around/solution

Couldn't connect to host server (odoo v11)

I was working on odoo, precisely in Website builder module while I was creating a website via the host IP address 192.168.1.2:9012, suddenly it crashes and shown me an Internal server error.
I tried to have a look at the log file and got this traceback,
2018-12-06 18:14:31,432 1 INFO ? odoo.sql_db: Connection to the database failed
2018-12-06 18:14:31,436 1 INFO ? werkzeug: 192.168.1.9 - - [06/Dec/2018 18:14:31] "GET /favicon.ico HTTP/1.1" 500 -
2018-12-06 18:14:31,441 1 ERROR ? werkzeug: Error on request:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 205, in run_wsgi
execute(self.server.app)
File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 193, in execute
application_iter = app(environ, start_response)
File "/usr/lib/python3/dist-packages/odoo/service/server.py", line 250, in app
return self.app(e, s)
File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 166, in application
return application_unproxied(environ, start_response)
File "/usr/lib/python3/dist-packages/odoo/service/wsgi_server.py", line 154, in application_unproxied
result = handler(environ, start_response)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1318, in _call_
return self.dispatch(environ, start_response)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1292, in _call_
return self.app(environ, start_wrapped)
File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 599, in _call_
return self.app(environ, start_response)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1455, in dispatch
self.setup_db(httprequest)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1387, in setup_db
httprequest.session.db = db_monodb(httprequest)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1539, in db_monodb
dbs = db_list(True, httprequest)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 1506, in db_list
dbs = odoo.service.db.list_dbs(force)
File "/usr/lib/python3/dist-packages/odoo/service/db.py", line 369, in list_dbs
with closing(db.cursor()) as cr:
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 634, in cursor
return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 178, in _init_
self._cnx = pool.borrow(dsn)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 517, in _locked
return fun(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 585, in borrow
**connection_info)
File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: No route to host
Is the server running on host "172.17.0.4" and accepting
TCP/IP connections on port 5432 ?
I believe that's a network problem, I couldn't connect to the host server. do you have any idea about this please?
Thank you.
The error is from Odoo server because it cannot connect to the PostgreSQL database. First make sure your database service is running and available.
From your ip addresses I assume you are running database locally in some kind of virtualization environment like Docker. If you are not able to connect, please describe your environment in more detail. This will make it possible for stackoverflowers to help you.

Using PostgreSQL with App Engine Standard

I trying to use postgres on app engine standard with python2.7 environment.
I use sqlalchemy + pg8000 for connection, connection string looks like:
postgresql+pg8000://user:password#/dbname?unix_sock=/cloudsql/project:us-central1:db
It works on local machine, but when I deploy it, I receive an error:
AttributeError: 'Connection' object has no attribute '_usock'
How to configure the connection to the database?
Full traceback:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/e416f9a06334486a/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/main.py", line 15, in <module>
db.engine.execute('select ')
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2074, in execute
connection = self.contextual_connect(close_with_result=True)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2123, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/base.py", line 2158, in _wrap_pool_connect
return fn()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 400, in connect
return _ConnectionFairy._checkout(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 788, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 529, in checkout
rec = pool._do_get()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 1193, in _do_get
self._dec_overflow()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/util/langhelpers.py", line 66, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 1190, in _do_get
return self._create_connection()
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 347, in _create_connection
return _ConnectionRecord(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 474, in __init__
self.__connect(first_connect_check=True)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/pool.py", line 671, in __connect
connection = pool._invoke_creator(self)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/strategies.py", line 106, in connect
return dialect.connect(*cargs, **cparams)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/sqlalchemy/engine/default.py", line 412, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/pg8000/__init__.py", line 112, in connect
application_name, max_prepared_statements)
File "/base/data/home/apps/s~valid-song-196413/web-analytics-parser:20180926t131114.412842106933365078/lib/pg8000/core.py", line 1183, in __init__
self._usock.close()
AttributeError: 'Connection' object has no attribute '_usock'