Winerror 10061 no connection could be made because the target machine actively refused it
Winerror 10061 no connection could be made because the target machine actively refused it
pymongo.errors.ServerSelectionTimeoutError:localhost:27017:[WinError 10061]No connection could be made because the target machine actively refused it
I am following the tutorial python from w3schools. I just started the mongoDB chapter. I installed mongoDB and checked it with:
without getting an error.
But as soon as I enter the following code:
I get these messages and an error message at the bottom in cmd:
I also tried too disabling firewall temporarily but the error kept coming up.
Does anyone have an idea what is going wrong?
4 Answers 4
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
There is nothing wrong with your code.
If you have disabled your firewall, the most likely reason is that the MongoDB Service is not installed or running. On windows press the windows key and type services to open the services App. Check the service MongoDB Server is listed and has a Running status.
Try running this command in CLI:
If you see any error, then watch this video
https://www.youtube.com/watch?v=FwMwO8pXfq0
The video is called «How to Install MongoDB on Windows 10»
This video was helpful
I was trying to connect from Django. I am using Python 3.7 and earlier tried with the URI string provided for Python 3.6+ but it didn’t work in pyCharm or Jupyter. But later I chose URI string for Python version 3.4+ and it worked in Jupyter Notebook but got issue connecting from django project. So to solve this I installed mongodb application from https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.11-signed.msi which started mongoDB services on my machine. And without changing any previous code I am able to connect. Below is my code to connect to MongoDB from Django application:
In my case I put the wrong port in
You can check which port mongodb server is listening to (in windows) via
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it #130
Comments
zaazbb commented Apr 14, 2014
when running WebSocketManager example met a error:
The text was updated successfully, but these errors were encountered:
Lawouach commented Apr 14, 2014
God. you’re not lucky today. I will try to have a look asap. Sorry.
Lawouach commented Apr 14, 2014
I’m wondering if it’s not a limit in your Windows settings. XP isn’t known for being server friendly.
zaazbb commented Apr 14, 2014
I modify 2000 clients to 20 clients, the error is still exists.
Lawouach commented Apr 14, 2014
Indeed. I just tried and it seems Windows doesn’t quite like using «localhost». Could you change the «localhost» part to «127.0.0.1» (or your real ip) in the manager example above please? It did work for me.
zaazbb commented Apr 14, 2014
no, this error is still exists, Regardless use «127.0.0.1» or «192.168.1.100»(my real ip).
but, run other example, use the same ip and port, it’s ok.
Lawouach commented Apr 14, 2014
This is weird. I just tried (mind you on a Windows 7) and it worked just fine (not that fast though since on Windows, we’re bound to use select which is rather crap).
zaazbb commented Apr 14, 2014
the client example have the same problem.
(https://ws4py.readthedocs.org/en/latest/sources/clienttutorial/#built-in)
but, the example use websockets lib, is ok. (https://github.com/aaugustin/websockets/blob/master/example/client.py)
I’ll try those examples use another PC(under win xp) and win7 later.
zaazbb commented Apr 15, 2014
under win7 64bit, have the same error(ConnectionRefusedError).
zaazbb commented Apr 15, 2014
I find out the reason of this error.
Must start server before client. if no server running, the client will meet ConnectionRefusedError.
I made a low level mistake.
Close this issue, please.
thank you.
pkgandhi commented Jan 4, 2017
Hello, I have a similar issue. Do we have to put anything in the password if we do it via Windows Authentication via logging in via SQL Server Management Studio. Any help would be appreciated. Thank you!
ultravires commented Mar 13, 2018 •
Hello, may your ‘target’ does not support https, like this: http://www.hacker97.cn/, but your «target = ‘https://hacker97.cn/». You should make sure your target is right
SagarDaya379 commented Jun 10, 2018
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it iam getting this error plz help
sp98 commented Jul 12, 2018
When installing MongoDB, you have ‘complete’ and ‘custom’ option. Go with ‘custom’ option. It solved this issue for me. Not sure why though.
ujur007 commented Aug 19, 2018
I have the same error but I have already started the server before client.
VIkash2601 commented Aug 24, 2018
@zaazbb at #130 I did the same (placed the started the server before) but still having the same issue. Could you please help me?
Lawouach commented Aug 24, 2018
Hey all, I haven’t looked at this project for a long time so I apologise again if it is frustrating to you. I have moved one indeed.
However, if there is a PR with fix someday for this one from the community, I’ll be happy to release it.
Ronald-Saunfe commented Jan 11, 2019
This error is raised when the client has failed to connect to the server.
Chedeshri commented Feb 19, 2019
I don’t know why this issue is closed I have same error as most of you guys i.e «ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it».
Anyway i tried every possible solution mentioned in above list :
apparently none of this had worked for me.
lucky630 commented Feb 26, 2019 •
found the solution after spending 2 hours of search
server.py file
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = » port = 5555 s.bind((host, port)) s.listen(5) while True: c, addr = s.accept() print(‘Got connection from’, addr) c.send(b’Thank you for connecting’) c.close()
client.py file
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = ‘server ip address..’ port = 5555 try: s.bind((host, port)) except socket.error as e: print(str(e)) s.connect((host, port)) print(s.recv(1024)) s.close()
This worked for me. other solution like changing to ‘localhost’ or ‘127.0.0.1’ didn’t worked.
and you must start the server before client.
server is window machine and client is ubuntu machine.
SalihOsman1 commented May 15, 2019
I was able to resolve it by setting (debug=False) on my Flask server. It worked for both (localhost, and 127.0.0.1). Hope that works for some folks!
rohitgautamm commented Aug 14, 2019
change the port to 8080 or 8888 and the host to socket.gethostname()
hope it will help as it did help me
if the problem still exist please share the code
Utkarsh22Ahuja commented Sep 18, 2019
Chandlerrrr commented Feb 9, 2020
muhammedayman commented Feb 13, 2020
if you are using wamp or xamp like software run it before you ran the command
«python manage.py runserver»
this is related with settings means if you are using mysql connection in your program
ziyaetuk commented Feb 17, 2020
All i did was run «mongod», and tried connecting. The mongodb server needed to start.
BiswajitGhoshal commented Mar 13, 2020
njokuifeanyigerald commented Apr 13, 2020
am having the same issue whenever i use dj rest auth for django
Lawouach commented May 1, 2020
I think, at this stage, most comments here are related to the common connection error that can occur on any software. They don’t seem to be related to ws4py. I will therefore lock this issue.
Footer
© 2022 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.