Web2py is not connecting with my MySQL database - python

I have a system running on Google App Engine in Python with web2py.
Before it was connected with a Google Cloud SQL database.
Now I need it to connect to a database at DreamHost.
db = DAL ('mysql: // User: senha#mysql-apollo-apollo.apollosolucoes.com/bancodedados' driver_args = {
        }, Migrate_enabled = False, lazy_tables = True)
This generating me this error:
Traceback (most recent call last):   File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/restricted.py",
line 220, in restricted
    exec ccode in environment   File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/applications/frontend/models/b_db.py",
line 12, in
    }, Migrate_enabled = False, lazy_tables = True)   File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 7867, in init
    raise RuntimeError ("Failure to connect, tried% d times: \ n% s"% (attempts, tb)) RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):   File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 7845, in init
    self._adapter = ADAPTERS [self._dbname] (** kwargs)   File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 688, in call
    obj = super (AdapterMeta, cls) .__ call __ (* args, ** kwargs)   File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py"
line in 2728, in init
    if do_connect: self.reconnect ()   File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 648, in reconnect
    self.connection = f ()   File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py"
line in 2726, in connector
    self.driver.connect return (** driver_args)   File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/init.py",
line 81, in Connect
    return Connection (* args, ** kwargs)   File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/connections.py",
line 190, in init
    super (Connection, self) .__ init __ (* args, ** kwargs2) OperationalError: (2005, "Unknown MySQL server host
'mysql-apollo-apollo.apollosolucoes.com' (-1)")
Putting that host more User and password, and database in the program SQLyog I can connect perfectly.
When the connection was made to go to the Google Cloud SQL database went like this:
'unix_socket' '/ cloudsql / apollo-solutionworkshop: apollosystem-main'

Related

Can't connect to Cassandra using python but can through cqlsh

I'm trying to test my pod connection to Cassandra using python. This is the code that I have:
host = '<hostname>'
port_num = 9092
default_fetch_size = 5000
idle_heartbeat_interval = 30
idle_heartbeat_timeout = 30
connect_timeout = 10
executor_threads = 2
protocol_version = 4
db_keyspace = 'fraud'
auth_provider = PlainTextAuthProvider(username=username, password=password)
cluster = Cluster([host], port=port_num, auth_provider=auth_provider,
idle_heartbeat_interval=idle_heartbeat_interval,
idle_heartbeat_timeout=idle_heartbeat_timeout,
connect_timeout=connect_timeout,
protocol_version=protocol_version,
executor_threads=executor_threads)
session = cluster.connect()
And I get the error:
Traceback (most recent call last):
File "run.py", line 3, in <module>
CassProvider().test_cassandra()
File "/app/tmp_cassandra_connection.py", line 59, in test_cassandra
cassandra_connector = CassandraDbConnector().get_session()
File "/usr/local/lib/python3.6/site-packages/project/src/objects/type_objects.py", line 11, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "/app/tmp_cassandra_connection.py", line 41, in __init__
session = cluster.connect()
File "cassandra/cluster.py", line 1664, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 1700, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 1687, in cassandra.cluster.Cluster.connect
File "cassandra/cluster.py", line 3485, in cassandra.cluster.ControlConnection.connect
File "cassandra/cluster.py", line 3530, in cassandra.cluster.ControlConnection._reconnect_internal
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'<ip>:9092': OSError(None, "Tried connecting to [('<ip>', 9092)]. Last error: timed out")
but when I get on the same pod using bash I can connect to Cassandra using cqlsh without a problem using the same host, default port, username and password.
Do you know why the python code on the pod gives me problems but the cqlsh is working perfectly?
Thanks
'Unable to connect to any servers', {'<ip>:9092':
Try setting the port to 9042, which is the default.
port_num = 9042

Cant connect to sql server with mysql-connector

I'm trying to connect to mySQL using mysql-connector and I'm getting an error:
runfile('C:/Users/Idan/Desktop/תכנות/ניסויים/idk/adding_test/connect_to_db.py', >wdir='C:/Users/Idan/Desktop/תכנות/ניסויים/idk/adding_test')
Traceback (most recent call last):
File "C:\Users\Idan\Desktop\תכנות\ניסויים\idk\adding_test\connect_to_db.py", >line 13, in
database = 'temp'
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector_init_.py", >line 271, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 95, in init
self._in_transaction = False
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector\abstracts.py", >line 985, in connect
self._open_connection()
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 205, in _open_connection
ssl_options.get('verify_identity') or
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 193, in _get_connection
if client_flags & ClientFlag.SSL:
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector\network.py", >line 565, in init
super(MySQLTCPSocket, self).init()
TypeError: super(type, obj): obj must be an instance or subtype of type
I have tried searching online and I can't find problem with my code (and yes the password is correct):
import mysql.connector as mysql
db = mysql.connect(
host = 'localhost',
user = 'root',
password = '10iDun7lEvy3',
database = 'temp'
)
c = db.cursor()

Python package APSscheduler throws an error when starting scheduler if mongodb is used as a jobstore

I'm trying to run some code with APScheduler with MongoDB as a jobstore. I've downloaded pymongo and I tested it, so it does work. APScheduler will work when I instantiate the scheduler, but when I run scheduler.start() it throws the following error:
Traceback (most recent call last):
File "aps_ro.py", line 56, in <module>
scheduler.start()
File "/usr/lib/python3.8/site-packages/apscheduler/schedulers/background.py", line 33, in start
BaseScheduler.start(self, *args, **kwargs)
File "/usr/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 158, in start
store.start(self, alias)
File "/usr/lib/python3.8/site-packages/apscheduler/jobstores/mongodb.py", line 57, in start
self.collection.ensure_index('next_run_time', sparse=True)
File "/usr/lib/python3.8/site-packages/pymongo/collection.py", line 2028, in ensure_index
self.__create_index(keys, kwargs, session=None)
File "/usr/lib/python3.8/site-packages/pymongo/collection.py", line 1881, in __create_index
with self._socket_for_writes(session) as sock_info:
File "/usr/lib/python3.8/site-packages/pymongo/collection.py", line 195, in _socket_for_writes
return self.__database.client._socket_for_writes(session)
File "/usr/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1266, in _socket_for_writes
server = self._select_server(writable_server_selector, session)
File "/usr/lib/python3.8/site-packages/pymongo/mongo_client.py", line 1253, in _select_server
server = topology.select_server(server_selector)
File "/usr/lib/python3.8/site-packages/pymongo/topology.py", line 233, in select_server
return random.choice(self.select_servers(selector,
File "/usr/lib/python3.8/site-packages/pymongo/topology.py", line 192, in select_servers
server_descriptions = self._select_servers_loop(
File "/usr/lib/python3.8/site-packages/pymongo/topology.py", line 208, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
My actual code sample is as follows:
jobstores = {
'mongo': {'type': 'mongodb'},
'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')
}
executors = {...}
job_defaults = {...}
scheduler = BackgroundScheduler()
scheduler.configure(jobstores=jobstores, executors=executors, job_defaults=job_defaults, timezone=utc)
#scheduler.scheduled_job(trigger='cron', day_of_week=4, hour=22, minute=21, second=0)
def tester():
print("hello")
scheduler.start()
By default, the mongodb python driver will connect to a database on host localhost and port 27017.
So you will need to either:
make sure mongodb server is running on the same machine as the python code and is running, on the default port (you can test this easily by typing mongo at your favourite shell and checking you get a > prompt and not an error).
supply a connection string or connection arguments if mongodb is running on a different server or a different port.

Mongodb and Celery "pymongo.errors.OperationFailure: command createIndexes requires authentication"

I am working Celery with Mongodb( as backend and as a broker).
I follow this tutorial on how to set them up: https://skillachie.com/2013/06/15/intro-celery-and-mongodb/
When I have the security enable on the /etc/mongod.conf file like this:
security:
authorization: enabled
and I call the .get() to get the results of the tasks that I have set up I get this error:
Traceback (most recent call last):
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/kombu/utils/__init__.py", line 323, in __get__
return obj.__dict__[self.__name__]
KeyError: 'collection'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/celery/result.py", line 169, in get
no_ack=no_ack,
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/celery/backends/base.py", line 229, in wait_for
meta = self.get_task_meta(task_id)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/celery/backends/base.py", line 307, in get_task_meta
meta = self._get_task_meta_for(task_id)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/celery/backends/mongodb.py", line 158, in _get_task_meta_for
obj = self.collection.find_one({'_id': task_id})
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/kombu/utils/__init__.py", line 325, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/celery/backends/mongodb.py", line 246, in collection
collection.ensure_index('date_done', background='true')
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/collection.py", line 2028, in ensure_index
self.__create_index(keys, kwargs, session=None)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/collection.py", line 1894, in __create_index
session=session)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/collection.py", line 250, in _command
user_fields=user_fields)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/pool.py", line 613, in command
user_fields=user_fields)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/network.py", line 167, in command
parse_write_concern_error=parse_write_concern_error)
File "/home/celeryProject/celeryProject/lib/python3.6/site-packages/pymongo/helpers.py", line 159, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: command createIndexes requires authentication
But when I disable the security it is working!
I also tried to change the roles on the user on mongodb and nothing happened.
Also, I have tried to log in with that way:
BROKER_URL = 'mongodb://tester:123456#178.128.250.181:27017/test?authSource=admin'
celery = Celery('EOD_TASKS',broker=BROKER_URL)
Is this a security problem or I can ignore it and move on?
if i'm not mistaken, using authorization: enabled means you need to setup a user/pass to login in order to query the mongodb. by default it is left wide open, which is a security consideration

How to connect web2py with mysql on Windows 10

After adding
db = DAL('mysql://admin:admin#localhost/web2py')
I got this errors..
Failure to connect, tried 5 times: Traceback (most recent call last): File "C:\Projects\web2py\gluon\packages\dal\pydal\base.py", line 457, in init self._adapter = adapter(**kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters__init__.py", line 39, in call obj = super(AdapterMeta, cls).call(*args, **kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\base.py", line 369, in init super(SQLAdapter, self).init(*args, **kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\base.py", line 53, in init self.reconnect() File "C:\Projects\web2py\gluon\packages\dal\pydal\connection.py", line 154, in reconnect self.connection = self.connector() File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\mysql.py", line 51, in connector return self.driver.connect(**self.driver_args) File "MySQLdb/init.py", line 81, in Connect File "MySQLdb/connections.py", line 193, in init TypeError: 'password' is an invalid keyword argument for this function
I have installed mysql, mysql-connector for python, mysql-client, python2.7 and so on
db = DAL('mysql://admin:admin#localhost/web2py')
I expecting this will be connect but not 😒😒😒
Try something like this
uri = mysql://user:password#host/databasename
And also, use Python 3 goodluck :)))

Categories