Before I begin please respect that I'm a newbie, ask me what more information you need to solve this problem rather than close the question or something. ;) OK. I am trying to connect my Django developer server to a MySQL database that is being hosted on a remote server. I've installed MySQL and MySQL-Python and have these settings in 'settings.py':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database_name', # Or path to database file if using sqlite3.
'USER': 'database_user', # Not used with sqlite3.
'PASSWORD': 'database_password', # Not used with sqlite3.
'HOST': 'db9.subsys.no', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
When i try to start the developer server using python manage.py runserver I get this:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 411, in get_server_version
self.cursor()
File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 81, in Connect
File "build/bdist.macosx-10.7-intel/egg/MySQLdb/connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'db9.subsys.no' (60)")
When I changed 'HOST': 'db9.subsys.no' to 'HOST': '' I got this instead:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 411, in get_server_version
self.cursor()
File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 81, in Connect
File "build/bdist.macosx-10.7-intel/egg/MySQLdb/connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'database_user'#'localhost' (using password: YES)")
Is it not possible to connect to MySQL using the developer server or do I need to do some kind of configuration on with the database? Reply if you have the answer or need more information.
Big Thanks in Advance!
Three things you should make sure of if you want to connect to a remote MySQL server:
The server is using networking and not sockets (there is no skip-networking line in my.cnf), and the server is listening on the public IP (with bind-address).
Your firewall allows remote access to the MySQL port, which is 3306 by default.
The user is allowed remote access:
GRANT ALL ON someDatabase.* to someUser#some.remote.ip IDENTIFIED BY 'foopass';
Just a quick sanity check - I assume you replaced the placeholder values (e.g. *database_name*) with the actual values?
Also, have you tried connecting to the database over the command line first (on your local development machine - not through some sort of SSH connection to a VPS etc.) to check that it's reachable from wherever you're developing from, e.g. mysql -u - p? If not, it probably means your web hosting company (I'm making an assumption that this isn't your database - please correct me if this is wrong and/or see #Burhan Khalid's answer) doesn't allow external connections to that database server and you won't be able to connect remotely from any software - this has nothing to do with Django. In this case either contact the hosting company to find out what port number to use (or if external database connections are even allowed under their firewall rules) or use a local database for development and then populate the production database from a dump-file of your local database. Here is a tutorial on this process - http://php.about.com/od/learnmysql/ss/mysql_backup.htm.
In my opinion this is a better way of doing things, as it is probably easier and more practical to develop locally and then upload. It can also prevent you from making a costly mistake if that winds up being the live database and you run one of the manage.py commands that can wipe out a table(s)!
You can use the database with the development server.
When you keep the host and port blank, django uses the default port to connect to the database on the local machine. In your case, you are getting an error because the username or password that you are using while connecting to the database on localhost is incorrect.
While connecting to a remote server, please make sure that you are
allowed to access it remotely. MySQL doesnt allow remote connections
by default.
Also, make sure that the port you are trying to connect
on is not blocked by a firewall.
Read this to figure out what you need to do to allow this behaviour: http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
I hope this helps you figure out the solution.
Try using an IP-Adress instead of 'db9.subsys.no' after the 'HOST': Tag.
Related
I'm trying to establish a connection to MySQL server from IDLE and I can't figure out why I'm getting an error.
>>> dbconfig = {'host': '127.0.0.1',
'user': 'vsearch',
'password': 'vsearchpasswd',
'database': 'vsearchlogDB'}
>>> import mysql.connector
>>> conn = mysql.connector.connect(**dbconfig)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
conn = mysql.connector.connect(**dbconfig)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 95, in __init__
self.connect(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/abstracts.py", line 719, in connect
self._open_connection()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 208, in _open_connection
self._do_auth(self._user, self._password,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/connection.py", line 137, in _do_auth
packet = self._protocol.make_auth(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/protocol.py", line 99, in make_auth
packet += self._auth_response(client_flags, username, password,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mysql/connector/authentication.py", line 190, in get_auth_plugin
raise errors.NotSupportedError(
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
I've tried these suggestions I found on stackoverflow :
shutting down mysql.server, installing mysql-connector-python and restarting mysql.server
passing an auth_plugin argument to the connect() method (as seen below)
auth_plugin='mysql_native_password'
made sure MySQL in listening to port 3306 (answer below)
localhost:mysql (LISTEN)
Versions:
mysql Ver 8.0.32 for macos12.6 on x86_64 (Homebrew)
Python 3.9.1
MacOS 12
Managed to fix issue by uninstalling MySQL connector and reinstalling it. Had issues with permissions so make sure you have permissions to read and write in connector directories.
This tutorial might help if your trying to connect to MySQL with MySQL-connector-python :
https://pynative.com/python-mysql-database-connection/
I'm a novice trying to spin up my first webapp with a combination of Fly.io, Django, and a postgres DB but I'm having some trouble and can't find an answer in walkthroughs or Q&A.
I've set up a simple "Hello world" Django app (models.py is empty so far) and I'm trying to get all the components up and running before I build it out any further.
I've successfully deployed my app on Fly.io with no errors
I've created a postgres cluster on Fly.io using the instructions here: https://fly.io/docs/postgres/
I've attached the cluster to my app, which generates a DB and sets an environment variable with the appropriate details (username, password, port, host, dbname)
I've updated my settings.py file:
DATABASES = {}
DATABASES["default"] = dj_database_url.config(conn_max_age=600, ssl_require=True)
I've added to my fly.toml:
[[services]]
internal_port = 5432 # Postgres instance
protocol = "tcp"
# Open port 10000 for plaintext connections.
[[services.ports]]
handlers = []
port = 10000
I've confirmed I can get into the psql shell with flyctl postgres connect -a MYAPP-pg
But unfortunately when I run python manage.py migrate to check that everything is working, I get the following error:
File "<my_path>\venv\lib\site-packages\django\db\backends\base\base.py", line 282, in ensure_connection
self.connect()
File "<my_path>\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "<my_path>\venv\lib\site-packages\django\db\backends\base\base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "<my_path>\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "<my_path>\venv\lib\site-packages\django\db\backends\postgresql\base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "<my_path>\venv\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "top2.nearest.of.MYAPP-pg.internal" to address: Unknown host
Any ideas what might be happening? Any help would be very much appreciated!
I am a fairly new to web developement.
First I deployed a static website on my vps (Ubuntu 16.04) without problem and then I tried to add a blog app to it.
It works well locally with PostgreSQL but I can't make it work on my server.
It seems like it tries to connect to Postgres with my Unix user.
Why would my server try to do that?
I did create a database and a owner via the postgres user, matching the login information in settings.py, I was expecting psycopg2 to try to connect to the database using these login informations:
Settings.py + python-decouple:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': config ('NAME'),
'USER': config ('USER'),
'PASSWORD': config ('PASSWORD'),
'HOST': 'localhost',
'PORT': '',
}
}
This is the error message I get each time I try to ./manage.py migrate
'myportfolio' is my Unix user name, the database username is different:
Traceback (most recent call last):
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/myportfolio/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "myportfolio"
FATAL: password authentication failed for user "myportfolio"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/myportfolio/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 79, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/loader.py", line 206, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
if self.has_table():
File "/home/myportfolio/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/myportfolio/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/myportfolio/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "myportfolio"
FATAL: password authentication failed for user "myportfolio"
I tried to:
delete my django code, re install
delete/purge postgres and reinstall
modify pg_hba.conf local to trust
At one point I did create a django superuser called 'myportfolio' as my unix user: could this have create a problem ?
As per the error, it is clear that the failure is when your Application is trying to postgres and the important part to concentrate is Authentication.
Do these steps to first understand and reproduce the issue.
I assume it as a Linux Server and recommend these steps.
Step 1:
$ python3
>>>import psycopg2
>>>psycopg2.connect("dbname=postgres user=postgres host=localhost password=oracle port=5432")
>>>connection object at 0x5f03d2c402d8; dsn: 'host=localhost port=5432 dbname=postgres user=postgres password=xxx', closed: 0
You should get such a message. This is a success message.
When i use a wrong password, i get this error.
>>>psycopg2.connect("dbname=postgres user=postgres host=localhost password=wrongpassword port=5432")
>>>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line 130, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
When there is no entry in pg_hba.conf file, i get the following error.
>>> psycopg2.connect("dbname=postgres user=postgres host=localhost password=oracle port=5432 ")
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "::1", user "postgres", database "postgres", SSL on
FATAL: no pg_hba.conf entry for host "::1", user "postgres", database "postgres", SSL off
So, the issue is with password. Check if your password contains any special characters or spaces. if your password has spaces or special characters, use double quotes as i used below.
>>> psycopg2.connect(dbname="postgres", user="postgres", password="passwords with spaces", host="localhost", port ="5432")
If all is good with the above steps and you got success messages, it is very clear that the issue is with your dsn.
Print the values passed to these variables.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': config ('NAME'),
'USER': config ('USER'),
'PASSWORD': config ('PASSWORD'),
'HOST': 'localhost',
'PORT': '',
}
}
Validate if all the values are being substituted appropriately. You may have the correct password for the user but the dsn is not picking the correct password for the user. See if you can print the dsn and validate if the connection string is perfectly being generated. You will get the fix there.
So I was just stuck on this problem and I thought I'd save whoever comes across this post some time by posting the actual commands. This was done on my raspberry pi.
sudo su - postgres
postgres#raspberrypi:~$ psql
postgres=# CREATE DATABASE websitenamehere
postgres=# CREATE USER mywebsiteuser WITH PASSWORD 'Password';
postgres=# GRANT ALL PRIVILEGES ON DATABASE websitenamehere to mywebsiteuser;
postgres=# \q
Done, you have now created a user.
What is setup as user in config ('USER'). Following the error:
FATAL: password authentication failed for user "myportfolio"
user is myportfolio, so you will need to create that user if it does not exist.
I had something similar. My issue was that I did not set the environment variables correctly so it couldn't connect. Ensure that if you go to Edit Configurations, then Environment Variables, and put in your answers in that column.
This problem might also occur if you have some special characters within your password that Postgres cannot cope with (unless you do some special encoding).
Try something like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
For me, I had the wrong port. Additional characters.
This solved for me:
from sqlalchemy import create_engine
connection_string_orig = "postgres://user_with_%34_in_the_string:pw#host:port/db"
connection_string = connection_string_orig.replace("%", "%25")
engine = create_engine(connection_string)
print(engine.url) # should be identical to connection_string_orig
engine.connect()
from:
https://www.appsloveworld.com/coding/python3x/7/flask-alchemy-psycopg2-operationalerror-fatal-password-authentication-fail
I created a new EC2 Instance with Postgres on RDS. I confirmed that I can connect from the EC2 instance to the database using psql without any issue which means my security settings are fine.
However, when I try to run manage.py runserver or manage.py dbshell (from the virtualenv) Django hangs then eventually gives a timeout error:
psql: could not connect to server: Connection timed out Is the server
running on host "whatever.rds.amazonaws.com"
(172.xxx.xxx.xxx) and accepting TCP/IP connections on port 5342?
Traceback (most recent call last): File "manage.py", line 22, in
execute_from_command_line(sys.argv) File "/home/ubuntu/Env/xxxx/lib/python3.5/site-packages/django/core/management/init.py",
line 363, in execute_from_command_line
utility.execute()
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/init.py",
line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/base.py",
line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/base.py",
line 330, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/core/management/commands/dbshell.py",
line 22, in handle
connection.client.runshell()
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/db/backends/postgresql/client.py",
line 66, in runshell
DatabaseClient.runshell_db(self.connection.get_connection_params())
File "/home/ubuntu/Env/ss2017/lib/python3.5/site-packages/django/db/backends/postgresql/client.py",
line 58, in runshell_db
subprocess.check_call(args)
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['psql', '-U', 'db_name',
'-h', 'whatever.rds.amazonaws.com', '-p', '5342', 'user_name']'
returned non-zero exit status 2
I tried creating a new copy of the Django app to see if there were perhaps corrupt files involved, and I played with some changes to my settings.py file, but no luck.
Any ideas?
Edit:
Settings.py (the important bits)
DEBUG = False
ALLOWED_HOSTS = ['localhost', '0.0.0.0', '127.0.0.1', 'compute.amazonaws.com']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'xxxxxxxx',
'PASSWORD': 'xxxxxxxx',
'HOST': 'whatever.us-west-2.rds.amazonaws.com',
'PORT': '5342',
}
}
I ended up creating a local postgres database on the EC2 server to see if any errors come up. When I tried to run makemigrations or migrate to set up the database I got a "relation does not exist" error. The stack trace pointed to a line in one of my views that looked something like this:
some_queryset = Model.objects.all()
some_queryset.delete() # <--- this line was the problem
Even though this is technically an acceptable way to delete all entries in a given table, Django (on the server) did not like the fact that the relationships of the given model did not exist.
I commented out the line and was able to connect to the database without any issues.
So for future readers - if your Django app hangs on runserver, but you can reach the RDS database from the EC2 instance, try setting up a local database to check for any issues.
exit status 2 usually means you've called psql with the wrong arguments. For me, a psql authentication error also triggered this exit code. My problem ended up being a typo in the DBPASSWORD environment variable that settings.DATABASES['default'] was using.
I have a MongoDB server running on my localhost. I wrote a simple Python program that reads/writes to the database using "localhost"; however, I want to give other clients access to my MongoDB server. For now, I am not concerned about access security and would like to grant access to anyone. How should I configure the Mongo Server to do this?
Here is the simple program connecting to localhost.
from pymongo import MongoClient
connection = MongoClient("Localhost")
db = connection.hockey.players
results = db.find()
print()
print('+-+-+-+-+-+-+-+-+-+-+-+-+-+-')
for record in results:
print(record['name'] + ',',record['position'])
connection.close()
The error message I'm getting:
File "C:/Users/Peter/PycharmProjects/Test/helloWorld.py", line 8, in
for record in results:
File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 1097, in next
if len(self.__data) or self._refresh():
File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 1019, in _refresh self.__read_concern))
File "C:\Python34\lib\site-packages\pymongo\cursor.py", line 850, in __send_message **kwargs)
File "C:\Python34\lib\site-packages\pymongo\mongo_client.py", line 777, in _send_message_with_response server = topology.select_server(selector)
File "C:\Python34\lib\site-packages\pymongo\topology.py", line 142, in select_server address))
File "C:\Python34\lib\site-packages\pymongo\topology.py", line 118, in select_servers self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: x.y.z.w:27017: timed out
Process finished with exit code 1
Below is my current localhost setup that works fine if I run it on my client which hosts the MongoDB. Current setup
Thanks
Give them your ip address and the port number (Default:27017) to connect to your server. Also edit the bindIp in the mongod.conf file as bindIp: 0.0.0.0. Ask them to connect to your database by using something like:
from pymongo import MongoClient
connection = MongoClient("mongodb://your_ip:yourport")
If you're on windows, create the configuration file mongod.cfg. And add the entry as
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
net:
bindIp: 0.0.0.0
port: 27017
Make sure you've already created log and db folder or change the path where your data and log folder are located.
Start the mongodb by specyfying thr configuration file.
Verify that you local interface is up. It should explain the timeout.
ifup lo