connection error while connecting mongodb using python - python-3.x

PYTHON CODE
from pymongo import MongoClient
if __name__ == "__main__":
client = MongoClient('mongodb://localhost:27017/')
..I even tried
client = MongoClient()
getting this error..
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it
I am using Windows 10, the version of pymongo is 3.0.3 and I am using python 3.5

Related

odbc connection timeout | python | VM Sql server

import pypyodbc as odbc
from configparser import ConfigParser
try:
config = ConfigParser()
config.read('config.ini')
hostname = config.get('Config', 'host')
database = config.get('Config', 'database')
username = config.get('Config', 'sql_login')
password = config.get('Config', 'sql_passw')
driver = '{/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.1.so.2.1}'
conn_string = f"DRIVER={driver};SERVER={hostname};DATABASE={database};UID={username};PWD={password}"
result = None
with odbc.connect(f'{conn_string}', timeout=60) as cnxn:
cursor = cnxn.cursor()
result = cursor.execute(query).fetchall()
print(conn)
if conn:
print('connected to the games database')
else:
print('no connection...')
except Exception as e:
print(e)
finally:
#conn.close()
print('db connection closed')
I am struggling with the odbc connection from my linux vm to a Windows vm running sqlserver. I am rly lost , I think I have tried everything. Port 1433 is open on the Windows vm , my linux server pings the windows VM.
I`ve tried to connect on Windows host to the sql server via sa login - its working.
I've turned off the Windows firewall and I still get the same error. First I was using pyodbc and later on i changed it to pypyodbc - nothing happend. trusted_connection=True - dosnt change anything.
After debugging this script the conn_string seems to be alright, also there is no difference if I connect to the IP adress or <computer_name>\SQLexpress.In the Microsoft documentation they suggested that the timeout timer was to short, I've changed it as well and I got still the same error.
Stackoverflow, please help :) !
Error :('HYT00', '[HYT00] [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired')

Error in connecting python client "Exception during establishing a SSL connection: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record"

I am trying to get a python ElasticSearch client to connect to a local OpenSearch server that is running via docker. Am unable to connect and keep getting
opensearch-node1 | [2021-09-25T00:09:09,526][ERROR][o.o.s.s.h.n.SecuritySSLNettyHttpServerTransport] [opensearch-node1] Exception during establishing a SSL connection: io.netty.handler.ssl.NotSslRecordException: not an SSL/TLS record:
Installed OpenSearch locally sing docker following these instructions https://opensearch.org/downloads.html
Tried various ways to get the python client to connect but all are failing.
# es = Elasticsearch(timeout=600, hosts="http://localhost:9200", http_auth=('admin', 'admin'), use_ssl=False, verify_certs=False)
es = Elasticsearch(timeout=600, hosts=["http://localhost:9200"])
es.ping()
python version: 3.9.7
ElasticSearch python lib: 7.15.0
Has anybody experiences this?
**** Figured it out ****
Need to have a client of at most 7.13.4 as per the docs opensearch.org/docs/clients/index
and as per this issues github.com/opendistro-for-elasticsearch/sample-code/issues/242, have to initiate the client like this for local dev
es = Elasticsearch(['https://admin:admin#localhost:9200/'],
use_ssl=False,
verify_certs=False,
ssl_show_warn=False)

pymongo 3.8 not work with mondob 4 and python 3.5

Connect to mongodb 4 server with pymongo 3.8 but get serverselection timeout error
pymongo.errors.ServerSelectionTimeoutError: IP:host: [Errno 104] Connection reset by peer
I have similar issue.
I could not connect at first then changed to master host.
After that the connection problem fixed. However, I still cannot CRUD or list collections. It throws
OperationFailure: Authentication failed.

python etcd3 randomly fails with failed: grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with: status = StatusCode.UNKNOWN

I have very simple setup. I have etcd 3.3 server.
I have code in python (3.6) ive installed etcd3 version 0.10.0
import etcd3
data = etcd3.client(host='my.host.net', port=2379).get('/exesiting/key'))
print( data )
Key exsist, server address is ok.
This code fails randomly with follwing error
failed: grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNKNOWN
details = "Failed to create subchannel"
debug_error_string = "{"created":"#1557133790.170407000","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2715,"referenced_errors":[{"created":"#1557133790.170402000","description":"Empty update","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":270}]}"
What is wrong? Do i need to clean up connections somehow?

cx_oracle TNS: Connect timeout

I am trying to link to a Oracle Database using cx_Oracle in python and keep getting the error:
DatabaseError: ORA-12170: TNS:Connect timeout occurred
Here is the code I am running:
import cx_Oracle
dsn_tns = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=*ip*)(PORT=*port*))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=*service_name*)))'
db= cx_Oracle.connect('*username*', '*password*', dsn_tns, encoding="UTF-8")

Resources