python multiprocessing socket.error: [Errno 111] Connection refused? - python-2.7

I am doing a simple server/client connection using multiprocessing in python 2.7.
When I run the client code in a seperate python shell, the connection is successful, but when I run the application as a whole, I get "socket.error: [Errno 111] Connection refused".
This is the Traceback:
Traceback (most recent call last):
File "./kaboom", line 276, in <module>
sequence.run(testEnv)
File "/e/m/amoreau/test_edit/kaboom/src/kbmSequence.py", line 271, in run
if testEnv.open() != SUCCESS:
File "/e/m/amoreau/test_edit/kaboom/src/kbmTestEnv.py", line 518, in open
queueManager = resultsClient.QueueServerClient()
File "/e/m/amoreau/test_edit/kaboom/resultsClient.py", line 15, in QueueServerClient
manager.connect()
File "/usr/lib64/python2.6/multiprocessing/managers.py", line 474, in connect
conn = Client(self._address, authkey=self._authkey)
File "/usr/lib64/python2.6/multiprocessing/connection.py", line 143, in Client
c = SocketClient(address)
File "/usr/lib64/python2.6/multiprocessing/connection.py", line 263, in SocketClient
s.connect(address)
File "<string>", line 1, in connect
socket.error: [Errno 111] Connection refused
Why does this happen? I have disabled all firewalls.

Howdie, I just had this problem. I know this is an old answer, but I found the answer in a related question. It's listed below. The issue is that the client is attempting to connect to the server before the server has created the socket.
Well, that's what it was in my case. Spawning the server off into another process takes a wee bit longer then the client attempting to connect. To test, I placed a sleep call in my client and sure enough, no more error.
Python Socket Error - Connection Refused

Related

tensorflow IOError: [Errno socket error] [Errno 111] Connection refused

I tried to run a demo of TensorFlow.The MNIST dataset has been download,but there exists one error. Who can tell me what's wrong? Thanks very much! The error detail as follows:
Extracting MNIST_data/train-images-idx3-ubyte.gz
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Traceback (most recent call last):
File "/home/linbinghui/文档/pycode/my_tensorflow_code/test_mnist.py", line 7, in <module>
mnist = input_data.read_data_sets("MNIST_data/", one_hot=False)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py", line 189, in read_data_sets
local_file = maybe_download(TEST_IMAGES, train_dir, SOURCE_URL + TEST_IMAGES)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/learn/python/learn/datasets/base.py", line 81, in maybe_download
urllib.request.urlretrieve(source_url, temp_file_name)
File "/usr/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "/usr/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 897, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 859, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 836, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 111] Connection refused
This code is attempting to download https://storage.googleapis.com/cvdf-datasets/mnist/t10k-images-idx3-ubyte.gz and failing. It failed because of "Connection Refused" which generally indicates that the remote end is not running a server on the port you tried to contact it on.
This URL refers a Google storage service. I was able to successfully download this file. Either you encountered a transient failure of Google's service, or some intermediary between you and Google caused this problem.
Normally "connection refused" is not caused by anything other than the intended remote end being unavailable (there's a computer there but no specific service). However, in the face of modern HTTP and HTTPS proxies, DNS redirection and the like, you could very well have encountered some feature of your business/school/home/government internet interdiction. HTTPS urls can be troubling to the entity hosting your internet service because it represents a private communication channel through which you could download malware or upload secrets. This troubling nature makes it more likely to be intercepted or redirected or disabled entirely.
I recommend that you troubleshoot this problem with wget/curl or similar on your machine. If those work well, consider a small python script with the requests package. Consider also the impact of environment variables on these utilities/libraries. Try repeating this procedure at network endpoints other than the one you're using.
If you find that the results of repeated tests are unstable even in the same network endpoint, perhaps you're facing local load balancers/proxies or some other transient local failure. When in doubt, contact your local network support team.

Connect to AS400 database with Django (ibm_db_django)

I have created a new project in Django and am following this tutorial to help me pull data from my remote database. Whenever I try to run migrate in manage.py I get the following error:
"C:\Program Files (x86)\JetBrains\PyCharm 2016.2.1\bin\runnerw.exe" C:\Users\ecjohnson\AppData\Local\Programs\Python\Python35-32\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.1\helpers\pycharm\django_manage.py" migrate U:/incoming_parts_monitor
Traceback (most recent call last):
File "C:\Users\ecjohnson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\ibm_db_dbi.py", line 585, in connect
conn = ibm_db.connect(dsn, '', '', conn_options)
SQLCODE=-30081
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ecjohnson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\base.py", line 199, in ensure_connection
self.connect()
File "C:\Users\ecjohnson\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
I've connected to this database before in other .NET web applications so I'm not sure why this is not working.
The sqlcode=-30081 is a generic "unable to connect" condition. Look to the configuration and connection details, on both the requesting and server systems, and review for any messaging about a connection issue on the server side [of possible assist is a review of the Display Log (DSPLOG) for the history (QHST), and then review of the joblog(s) of the job(s) that originated that messaging] as an indication that the communications-level connection was at least completed, but some error after that initial comm connection prevented establishing an actual database connection; e.g. perhaps the prestart job or the subsystem in which the database server jobs operate is not started.

Python 2.7 : socket.error error [Errno 111] - connection refused

I created a TCP server program (see server.py) to access the terminal of another computer (see client.py). When I use the client and server locally (only on my computer) everything is fine, however when the client is sending a request from a different computer, I receive this message on the client side :
Traceback (most recent call last):
File "client.py", line 11, in <module>
client.connect((serverIP, serverPort))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
Note : the server is the computer which is being accessed by the client.
'Connection refused' means there was nothing listening at the IP:port you tried to connect to.
It comes from the target system, which means that the connection request got there and the refusal came back, so it isn't a firewall issue.
Solved it. I had to use the IP given to in when running ifconfig (192.168.1.***). I was binding to localhost, and thus I could not connect to the server remotely.

Connection refused error while using python-Instagram API

I tried to run a simple code to extract data from Instagram using Python-Instagram module
The code is
from instagram.client import InstagramAPI
api = InstagramAPI(client_id='YOUR_CLIENT_ID',client_secret='YOUR_CLIENT_SECRET')
popular_media = api.media_popular(count=20)
I am getting a Connection refused error at the last lineline. Its because Python-Instagram module uses httplib2 module also. The error looks like this.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/anaconda/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1060, in connect
raise socket.error, msg
socket.error: [Errno 111] Connection refused
How to resolve this? Do I have to provide any connection specifications for using this module?

Accessing a URL in Windows machine from Docker Container

I am a newbie to Docker and this is what I am trying out.
I have a Windows machine on which I have installed Docker using Virtual Box as per this link. I have built a base Ubuntu Image. Now in the Windows Machine I have a Rest Service running that has to be accessed by the docker container. I am accessing it via Python Requests module. What IP should I give to the requests module's get method?
I have tried following
r = requests.get('http://172.17.42.1:8090/app/rest/names');
and
r = requests.get('http://172.17.0.2:8090/app/rest/names');
172.17.0.2 is the IP of Docker Container and 172.17.42.1 is the Bridge IP.
In both cases the error is Connection Refused
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 383, in reques
t
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.17.0.2', port=8090): Ma
x retries exceeded with url: /app/rest/names(Caused by <class 'socket.error'>:
[Errno 111] Connection refused)
However I can access a public URL available.
The bridge IP address should work. If it doesn't, it might be because the application on the Windows machine is not listening on all IP addresses, or maybe there is some kind of firewalling.
You can check that the application is listening on the right port (and on all addresses!) with netstat -a -n -o (on the Windows machine), as explained here.
Maybe the Windows machine is only listening on 127.0.0.1 …?