I am using the ftplib module and want to connect to FTP on my localhost. I am using the following code example:
import ftplib
f = ftplib.FTP()
f.connect("localhost")
f.login()
ls=[]
f.retrlines('MLSD',ls.append)
for entry in ls:
print entry
It gives me a socket.error: [Errno 61] Connection refused
How do i connect to my localhost and what am i doing wrong? Eventually i would want to send files from a client code to server code using ftplib, both running on the same machine. This is for a project, i know in reality you wouldn't have both on the same machine.
I am guessing the socket.error exception occurs on line 3, where you have connect().
Connection refused indicates that the operating system or the firewall rejected the connection. The most likely reason is that you don't actually have an FTP server running on your local machine.
You didn't say whether you do or you don't, and you didn't say what operating system you're using. But by default, operating systems don't come with an FTP server installed and running. So you need to install a compatible FTP server. A good one to consider is FileZilla Server.
Related
I have a remote Linux server setup where I am hosting a python script. The requirement is to connect to MongoDB that is hosted in a local windows machine. I understand that we can't directly access MongoDB as it allows only localhost:27017 by default.
Tried updating the mongo.cfg file by changing the properties under "net". However this didn't help. Can someone help me out in this case. I am getting the error below:
10.30.118.230:27017: [Errno 111] Connection refused
This is the code:
from pymongo import MongoClient
client = MongoClient("mongodb://{username}:{password}#{windows_system_ip_whereMongoDb_is_hosted}/{dbname}")
db = client.{dbname}
try:
db.command("serverStatus")
except Exception as e:
print(e)
else:
print("You are connected!")
client.close()
BY default windows firewall block all input connections in port 27017, you should enable the port 27017 in windows firewall to allow the connections through the port.
Configure Windows netsh Firewall for MongoDB
PyCharm remote debugging (pydevd) does not connect with the following message:
error: [Errno 10061] No connection could be made because the target machine actively refused it
How can I troubleshoot it?
The output console in PyCharm shows:
Starting debug server at port 21000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('*.*.*.*', port=21000, suspend=False)
Waiting for process connection...
Server stopped.
I checked the firewall and PyCharm is allowed for both incoming and outgoing connections.
10061 is WSAECONNREFUSED, 'connection refused', which means there was nothing listening at the IP:port you tried to connect to.
Though I see that you have validated its not a firewall issue, but still I would suggest to check the port numbers again with respect to the ones opened in windows firewall. Or to narrow down just run a simplehttpserver or icmp server at the same port and confirm.
In a direct link communication, it often means that you have already something connected to this port.
To check what process is hearing what port, check this SO question.
You can then either kill the program or change the port, depending of what you can do.
Without more information of the "remote tested", it is hard to know what is happening.
I was having the trouble as well (Server stopped as soon as the client connected).
Turned out that I had apparently too many breakpoints defined.
after having removed most of them and re-initiated my remote debug connection from the client (and having restarted the debug server in pycharm) it doesn't trigger anymore the "Server stopped." problem.
I am learning python socket programming. Everything works fine if I run locally (both server and client scripts). However, when I moved the server script to a VM (Ubuntu 14.04) and run the client script from the host os (Windows 7) I got this error:
ConnectionRefusedError: [WinError 10061] No connection could be made because the
target machine actively refused it
When I tried running the client inside the VM, it works just fine (except if I use the IP address i.e:192.168.1.6, I have to use it in both scripts). From my search, I found that linux does not activate the firewall by default. What did I do wrong?
Both machines can see each other ( i have set Samba between them, can ping others etc). This is really confusing for me.
Probably this may solve the problem.
You have a bind call in your server code, it looks like sock.bind(('127.0.0.1', 3333)), where 3333 is the server port number. Change the IP address to the empty string, or '0.0.0.0', so it would look like sock.bind(('', 3333)). Then start the client again.
The original bind call binds the server socket only to the loopback interface (lo), which works only within the VM. By binding to the wildcard address ('' or '0.0.0.0') the server will accept connections from any IP address.
I am trying to connect machine using the RPyC but it always says that connection refused.
I did on the python shell
import rpyc
rpyc.connect("hostname", port)
but it says connection refused. checked the firewall for the port. firewall allow this port.
Try using the exact same versions of both python and rpyc on client and server !
This means that you are not runnin the server side for rpyc
you need to donwload the source code for rpyc from here
https://github.com/tomerfiliba-org/rpyc/releases
then run:
python bin/rpyc_classic.py
where bin is in the source code folder
Once you have that running, you should be able to run the python code without any issues
I hope it works
default server binds to localhost, but the client needs to have hostname 'None' to do this correctly:
rpyc.connect(None, port)
I wrote an XML RPC server in python and a simple Test Client for it in python. The Server runs on a linux box. I tested it by running the python client on the same linux machine and it works.
I then tried to run the python client on a Mac and i get the following error
socket.error: (61, 'Connection Refused')
I can ping and ssh into the linux machine from the Mac. So i dont think its a configuration or firewall error.
Does anyone have any idea what could be going wrong?
The code for the client is as below:
import xmlrpclib
s = xmlrpclib.ServerProxy('http://143.252.249.141:8000')
print s.GetUsers()
print s.system.listMethods()
"Connection Refused" means the connection was REFUSED - the machine 143.252.249.141 is up, and in the network, but is not accepting connections on port 8000 - it is actively refusing them.
So maybe the server software isn't running on the server? Or is running in another port? Or is bound to a different IP address?