Home > OS >  How to access localhost or 127.0.0.1 on a Windows machine from Ubuntu Production Server?
How to access localhost or 127.0.0.1 on a Windows machine from Ubuntu Production Server?

Time:11-29

I need to fetch some data from a biometric device connected to the customer's PC and return it back to my production server. I'm using a Mantra MFS100 Biometric Device to capture biometric data of the user. According to Mantra's document the biometric service will be running in 127.0.0.1. I'm able to utilize different endpoints and fetch the data required locally(using pycharm IDE windows) but when trying from my production Ubuntu Server it does not work.

The biometric service will be running on port range 11100 - 11120. To use the service I need to discover the port on which the service is running. Code to discover the service:

import requests

for port in xrange(11100, 11122, 1):
 response = requests.request('RDSERVICE', 'http://localhost:%s' % str(port), headers=headers, data=data)
 if response.status == "READY":
  device_port = port
 if port == 11121:
  print "Fingerprint device is not connected"

If the service is READY, I can move on to capture the device data:

import requests

response = requests.request('CAPTURE', 'http://localhost:%s/rd/capture' % device_port, headers=headers, data=data)
print response.text

This works when I'm trying from Local Windows IDE and endpoint as Localhost or 127.0.0.1 but does not work when I try from Ubuntu Server. When trying from the Ubuntu Server I get the following error:

HTTPConnectionPool(host='127.0.1.1', port=11100): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f677d12cf10>: Failed to establish a new connection: [Errno 111] Connection refused',))

I also tried passing the user's ip as the endpoint to no avail:

import requests
import socket

ip_address = socket.gethostbyname(socket.gethostname())
response = requests.request('CAPTURE', 'http://%s:%s/rd/capture' % (ip_address, device_port), headers=headers, data=data)

How can I access Window's Localhost from Ubuntu Server(NGINX) in Python?

Edit:

This is the request, response data from the document: Request:

RDSERVICE * HTTP/1.1
HOST: http://127.0.0.1:[port]
EXT: APP_NAME

Response:

HTTP/1.1 200 OK
CACHE-CONTROL:no-cache
LOCATION:http://127.0.0.1:<rd_service_port>
Content-Length: length in bytes of the body
Content-Type: text/xml
Connection: Closed
<RDService status="READY|USED|NOTREADY|..." info="provider info for display purposes">
<Interface id="CAPTURE" path="/rd/capture" />
<Interface id="DEVICEINFO" path="/rd/info" />
</RDService>

CodePudding user response:

I solved this by executing the logic as ir.actions.client action with Javascript instead of Python. I'm able to access Localhost when I execute the logic as a client action.

  • Related