Pymongo Installation & Executing on MacOS - python

May i know why i couldn't run the pymongo on MacOS? I installed the pymongo with
sudo easy_install pymongo
but i not sure why will i getting this error
conn = Connection(ip)
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/connection.py", line 180, in __init__
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/mongo_client.py", line 269, in __init__
pymongo.errors.ConnectionFailure: could not connect to 192.168.0.1:27017: [Errno 51] Network is unreachable
thus i google and found i haven't initiate the pymongo yet, then i tried to run
mongod
mongo
./mongod
then it returned me command not found. tried to execute this
sudo export PATH=$PATH:/usr/local/mongodb/bin
Anyone know what's happening to my installation and how could i fix it? Thanks.

You have to install the mongodb server for osx: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

Related

Python mariadb module does not connect to database on network

I am trying to connect to a mariadb-database on my local network. using Python.
import mariadb
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
Output is:
Traceback (most recent call last):
File "/Users/localuser/PycharmProjects/SQL/main.py", line 20, in <module>
cursor = mariadb.connect(host='192.168.178.77', user='someuser', password='somepass', db='temps')
File "/Users/user/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/__init__.py", line 142, in connect
connection = connectionclass(*args, **kwargs)
File "/Users/localuser/.conda/envs/SQL/lib/python3.10/site-packages/mariadb/connections.py", line 86, in __init__
super().__init__(*args, **kwargs)
mariadb.OperationalError: Can't connect to server on '192.168.178.77' (60)
I can connect via Pycharms Database functionality and send SQL Statements.
I also can use DB management tools from that very host and use data without any issue.
It even works from my phone.
This code is the only place where I get an error.
OS is MacOS13.0.1
Thank You!
This happens due to a bug in MariaDB Connector/C. (Issue CONC-612).
The issue was fixed in C/C Version 3.3.3 - which is available via brew:
After
brew update
brew upgrade mariadb-connector-c
connection should work as expected.
I've got the same problem recently. Add port variable and check other. If doesn't help, try mysql-connector-python it works similar. Or install mariadb connector manually

Stuck with a MySQLdb SSL connection error in Python2.7

I have to maintain an old website built using Python2.7 that needs to continue working until we've finished creating a completely new version with more modern tools. Now this old website needs access to a remote MySQL database (connection is set up and working correctly), which so far has worked using the following:
import MySQLdb
db = MySQLdb.connect(host=Host,user=User,passwd=Pass,db=DBse)
Now the server has been upgraded from Ubuntu 18.04. to Ubuntu 20.04., and while I managed to install pip and MySQLdb for Python2.7, I now get the following error for the lines above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The SSL connection works fine in Python3 or directly from the command line.
Is there anything I can do to make this work?
Locate and add the line skip_ssl in /etc/mysql/my.cnf ( have tried this on MySQL 8.0.29 , Ubuntu 18)
This was the only thing that worked for me.
[mysqld]
skip_ssl

Teradata pypyodbc SQL_INVALID_HANDLE

While connecting pypyodbc with teradata i am getting SQL_INVALID_HANDLE
OS - Red Hat 4.4.7-17
Python Version - 2.6.6
I am not having administrative privilages to install the pypyodbc so i have downloaded the module, set pythonpath and imported it.
Done the required exports to point the python module to find the correct libodbc.so
export LD_LIBRARY_PATH=/opt/teradata/client/15.10/odbc_64/lib/
export ODBCINST=/opt/teradata/client/ODBC_64/odbcinst.ini
export ODBCINI=/opt/teradata/client/ODBC_64/odbc.ini
used the below code to create a db connection
pypyodbc.connect("Driver={Teradata};DBCNAME=<DB>;UID=<UNAME>;PWD=<PASS>")
The odbc connection string i have used is correct. I have tested using the below approach
/opt/teradata/client/15.10/bin/tdxodbc64 -C "Driver={Teradata};DBCNAME=<DB>;UID=<UNAME>;PWD=<PASS>"
**Note:**I am not using teradata OOTB python module because it works with a higher version of python which i cannot install.
Error
File "<stdin>", line 1, in <module>
File "<LOCAL_PATH>/pypyodbc.py", line 2421, in __init__
AllocateEnv()
File "<LOCAL_PATH>/pypyodbc.py", line 1000, in AllocateEnv
check_success(SQL_NULL_HANDLE, ret)
File "<LOCAL_PATH>/pypyodbc.py", line 990, in check_success
ctrl_err(SQL_HANDLE_ENV, ODBC_obj, ret, False)
File "<LOCAL_PATH>/pypyodbc.py", line 970, in ctrl_err
raise ProgrammingError('', 'SQL_INVALID_HANDLE')
pypyodbc.ProgrammingError: ('', 'SQL_INVALID_HANDLE')
any guidance on the matter is helpful
You need to install some packages. You can use this command:
sudo yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
This wiki will help you.
https://github.com/mkleehammer/pyodbc/wiki

Permission Denied Error When opening Socket to APNS on Google AppEngine Development

I'm trying to make my app engine server send APNS notifications, and for that I'm using template code I got from this project (which is said to work, so it's possible):
https://github.com/GarettRogers/appengine-apns-gcm
For now, I want to make this work on my local development.
When getting to actually trying to open the socket, I get the error stack below.
My guess is that maybe app engine needs sudo permissions to do this (I'm using a mac). If so - does anyone know how I can make app engine run with sudo permissions?
If not - can anyone tell me what the problem is and how to fix it?
Thanks.
File "/Users/xxx/Downloads/XXX/ssl.py", line 392, in wrap_socket
ciphers=ciphers)
File "/Users/xxx/Downloads/XXX/ssl.py", line 114, in __init__
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
File "/Users/xxx/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/dist27/socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
INFO 2014-04-15 19:42:02,488 module.py:627] default: "POST /content/create_action HTTP/1.1" 500 228
File "/Users/xxx/Desktop/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/remote_socket/_remote_socket.py", line 1112, in getsockopt
raise _SystemExceptionFromAppError(e)
error: [Errno 13] Permission denied
Apply this: "ImportError: No module named _ssl" with dev_appserver.py from Google App Engine
The question/answer explains it all, I won't go into detail, It's a long standing SDK deficiency, this manual method patches it, you need to apply it each time you update the SDK
I solved this via
pip install requests-toolbelt -t lib
then add
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
source: Can Python Requests library be used on Google App Engine?

Having an issue with setting up MySQLdb on Mac OS X Lion in order to support Django

So I am pretty sure that I have managed to dork up my MySQLdb installation. I have all of the following installed correctly on a fresh install of OS X Lion:
phpMyAdmin
MySQL 5.5.16
Django 1.3.1
And yet when I try to run "from django.db import connection" in a django console, I get the following:
from django.db import connection Traceback (most recent call
last): File "", line 1, in File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/init.py",
line 78, in
connection = connections[DEFAULT_DB_ALIAS] File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py",
line 93, in getitem
backend = load_backend(db['ENGINE']) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py",
line 33, in load_backend
return import_module('.base', backend_name) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py",
line 35, in import_module
import(name) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/backends/mysql/base.py",
line 14, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/[my
username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
2): Library not loaded: libmysqlclient.18.dylib Referenced from:
/Users/[my
username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found
I have no idea why this is happening, could somebody help walk me through this?
I found the following solution for this issue. It worked for me. I have encountered this problem when I was running python console from PyCharm.
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Easy,
edit your .bash_profile (vi ~/.bash_profile) somewhere in that add the following line:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
This line assumes your mysql install directory is in /usr/local/mysql/.
This will solve executing via python interrupter launched in shell (the .bash_profile exports the path needed by the MySQLdb module to load the ' libmysqlclient.18.dylib').
If you are having this issue with a Python IDE like PyCharm add the DYLD_LIBRARY_PATH variable to the launching module configuration.
I hope this helps :)
Also,
To fully understand this problem, read the following section:
http://mysql-python.sourceforge.net/FAQ.html#importerror
This explains this error in detail
Install pip if you haven't already, and run
pip install MySQL-Python

Categories