python-db | Relevant codes for python to operate the database
kandi X-RAY | python-db Summary
kandi X-RAY | python-db Summary
Relevant codes for python to operate the database
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of python-db
python-db Key Features
python-db Examples and Code Snippets
Community Discussions
Trending Discussions on python-db
QUESTION
Hello fellow AWS contributors, I’m currently working on a project to set up an example of connecting a Lambda function to our PostgreSQL database hosted on RDS. I tested my Python + SQL code locally (in VS code and DBeaver) and it works perfectly fine with including only basic credentials(host, dbname, username password). However, when I paste the code in Lambda function, it gave me all sorts of errors. I followed this template and modified my code to retrieve the credentials from secret manager instead.
I’m currently using boto3, psycopg2, and secret manager to get credentials and connect to the database.
List of errors I’m getting-
- server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request
- could not connect to server: Connection timed out. Is the server running on host “db endpoint” and accepting TCP/IP connections on port 5432?
- FATAL: no pg_hba.conf entry for host “ip:xxx”, user "userXXX", database "dbXXX", SSL off
Things I tried -
- RDS and Lambda are in the same VPC, same subnet, same security group.
- IP address is included in the inbound rule
- Lambda function is set to run up to 15 min, and it always stops before it even hits 15 min
- I tried both database endpoint and database proxy endpoint, none of it works.
It doesn’t really make sense to me that when I run the code locally, I only need to provide the host, dbname, username, and password, that’s it, and I’m able to write all the queries and function I want. But when I throw the code in lambda function, it’s requiring all these secret manager, VPC security group, SSL, proxy, TCP/IP rules etc. Can someone explain why there is a requirement difference between running it locally and on lambda?
Finally, does anyone know what could be wrong in my setup? I'm happy to provide any information in related to this, any general direction to look into would be really helpful. Thanks!
...ANSWER
Answered 2022-Mar-20 at 23:33Following the directions at the link below to build a specific psycopg2 package and also verifying the VPC subnets and security groups were configured correctly solved this issue for me.
I built a package for PostgreSQL 10.20 using psycopg2 v2.9.3 for Python 3.7.10 running on an Amazon Linux 2 AMI instance. The only change to the directions I had to make was to put the psycopg2 directory inside a python directory (i.e. "python/psycopg2/") before zipping it -- the import psycopg2
statement in the Lambda function failed until I did that.
This the VPC scenario I'm using. The Lambda function is executing inside the Public Subnet and associated Security Group. Inbound rules for the Private Subnet Security Group only allow TCP connections to 5432 for the Public Subnet Security Group.
QUESTION
I am trying to implement an auto loader from csv to database in python. Here I used for loop
to read the column names in csv. Sometimes it might happen that the column names could be same as reserved keywords of MySQL. So I want to find out a way if I can filter such strings that are same as reserved keywords. I saw many posts who suggested to do it manually adding all the keywords in a new table and then compare. But there is high chance of loosing a keyword while doing so and also extremely laborious process.
Or would it be a feasable way to catch the error and process the letters from error? Would it be possible to identify like that?
So is there a way how to find out if my query in loop has an input string which is same as reserved keyword of MySQL using python. Or any alternative how to find?
I am aware how to handle a keyword Eg: with back tick or in square brackets. But that is second step. First I have to know if there is a string that could be a keyword. How do I do this without creating a table/list of keywords. I am sure some words might be missed or there could be a typo by adding manually.
I have did some research and found an interesting almost similar but not same question in the following link. This answer did not support my use. Escaping MySQL reserved words with Python dbapi
Looking forward for your support and encouragement. I am a total newbee in SQL. Thank you
...ANSWER
Answered 2021-Jun-22 at 13:13Not sure if this what you require but check it out;
Option 1: Here is a complete list of all the keywords in MySQL. You can compare your column names with them and modify them accordingly
QUESTION
I'm getting an error when I'm using the notify2 module.
ModuleNotFoundError: No module named 'dbus'
The error is from the notify2.py file.
When I tried pip install dbus
this was the output:
ANSWER
Answered 2021-May-26 at 08:00Try doing pip install dbus-python
. It worked for me on fedora 34.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install python-db
You can use python-db like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page