tortoise.exceptions.ConfigurationError: Unknown DB scheme: postgresql error - python

I'm learning tortoise and am trying to configure Postgres with register_tortoise looking like below:
register_tortoise(
app,
db_url="postgresql://postgres:password#localhost:5432/testdb",
modules={'models': ['db.models.users']},
generate_schemas=True,
add_exception_handlers=True
)
But I get this error
tortoise.exceptions.ConfigurationError: Unknown DB scheme: postgresql
ERROR: Application startup failed. Exiting.
Could someone help me figure out the error?

Related

Invalid transaction error with SQLAclhemy, sqlalchemy-aurora-data-api

I have a Falsk app that is using sqlalchemy-aurora-data-api the package to connect to MySQL db from the AWS RDS.
In the app I am using raw queries eg. f'SELECT * FROM customers WHERE id={id}'
And to execute this query I use
conn.execute(customer_query).one()
and this is the connection string that I use to connect to the dB, not using sessions here
conn = create_engine(f'mysql+auroradataapi://:#/{db_name}',
connect_args=dict(aurora_cluster_arn=cluster_arn, secret_arn=secret_arn)).connect()
There is a random error that comes unexpected
Some error occurred in fetching data from customers table (botocore.errorfactory.BadRequestException) An error occurred (BadRequestException) when calling the RollbackTransaction operation: Invalid transaction ID
(Background on this error at: https://sqlalche.me/e/14/dbapi)
I can't really figure out the solution to this problem.
How can I solve this problem?

Catch "Internal Server Errror" when database does not exist with Flask and SQLALchemy

I have a web application which uses Flask and SQLAlchemy on MySQL running on Google AppEngine ( i.e. gunicorn ).
My error handler looks like this:
#main.app_errorhandler(Exception)
def handle_error(e):
# ...some other code to interpret different errors...
return render_template("some_pretty_template.html")
The error handler works well for most errors, but database-level errors ( for clarity, query-level errors are fine ) are not caught and you see a nasty "Internal Server Error" plaintext message. For example, dropping the database triggers the nasty error.
How do I create a catchall for "database gone" errors ( and any other errors aside from a complete Flask failure )?

Unable to connect to SQL server using PYMSSQL

I encounter this problem when trying to connect to my SQL database:
OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (LAPTOP-B3TE2LKC)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (LAPTOP-B3TE2LKC)\n')
I am able to connect to my database with the very same credentials using PYODBC, so the access variables should be fine.
Does anyone know how to solve this error message? - I am using Python version 3.8.8 and PYMSSQL version 2.2.2.
This is my code, including the credentials I used to connect to this test database:
import pymssql
print(pymssql.__version__)
# Database credentials and variables
server = 'LAPTOP-B3TE2LKC\TESTEXPRESS'
user = 'FTP-user'
password = '1111'
database = 'TestA'
# Connect to SQL database
database_connection = pymssql.connect(server, user, password, database)
Any help is highly appreciated.

pyHive error TTransportException: Could not start SASL

I am trying to connect to remote hive using pyHive.
conn = hive.Connection(host='*********', port=10001, database='default', username='********',
auth='KERBEROS', kerberos_service_name='hive').cursor()
But I always got this error
**Notes: I already have the kerberos ticket
Is there something wrong with my configuration ?

OperationalError when trying to connect to a remote PostgreSQL server in Python

I have a task that asks:
You have two abstract reports made available to you on a PostgreSQL server located at: postgres://candidate.company.org/company
username = candidate password = abc
So I used this code to try connect to the database:
import psycopg2 as db
conn = db.connect(host='postgres://candidate.suade.org/company', database='randomname', user='candidate', password='abc', port='5432')
I received the following error message:
OperationalError: could not translate host name "postgres://candidate.suade.org/suade" to address: Unknown host
My experience of connecting to databases is limited. Can anyone see what I am doing wrong here?

Categories

Resources