Defining a Proxy used by the Azure IoT Hub Client (Python) - python

I am using the Azure IoT Hub Client SDK for Python. I am using a slightly modified version of the sample script from the github repo to upload files to the IoT Hub. Everything works fine as long as I do not have to use a proxy for outgoing connections.
I tried to understand how to configurate a proxy for this, but I did not find anything for the Python SDK. I searched also in the other SDKs and found some ProxySettings in the iothub_client_options.h of the C SDK. But I do not know how to set these settings in the python client (in case the settings are actually working).
I also found an issue that the connection over websockets needs some special format of the Linux environment variables. But I do not use websockets.
I tried to run my script both in Windows and Linux environments where the proxy system settings are correctly configured (Win: Internet settings, Linux: environment variables).
Is there any documentation on this topic? Does anybody how to configure a proxy either on windows or on linux?

Per my experience, I think you can run the python script using Azure IoTHub Client SDK without any proxy settings to communicate with Azure IoT Hub if the OS configured correctly the proxy.
However, there are some notes which need to be focused by using different protocol (such as HTTP, Socks, etc) configured in proxy server, as below.
Normally, the proxy server was configured for working on HTTP protocol which only allow the HTTP communication. So if using IoTHub Client within HTTP mode, the script will works fine, but not works within AMQP/MQTT mode.
If the proxy server was configured for working on Socks protocol, such as Socks4/Socks5, the script within any mode will works fine, because the Socks protocol just transmit datagram, not check the protocol type.
So please check which protocols be supported in your proxy server, then to use HTTP mode or configure Socks protocol for proxy to make the script works.

Related

Django, RestAPI, Microsoft Azure, website, virtual machine, ubuntu

I have developed a website and REST api using Django and Django REST Framework. On local machine they are working perfectly so my next step is trying to publish it on remote server. I chose Microsoft Azure.
I created a virtual machine with Ubuntu server 18.04 and installed everything to run my project there. While I run it locally on virtual machine it's working perfectly, at localhost:8000; my website and rest-api are showing.
Now I want it to publish to the world so it can be accessed under the IP of my virtual machine or some different address so everybody can access it. I was looking through azure tutorials on Microsoft website and google, but i cannot find anything working.
I don't want to use their Web App solution or Windows Server. It needs to be working with Ubuntu Virtual machine from Azure. Is it possible to do and if yes then how?
(Optional) Set your web application listen publicly on 80 port for http or 443 port for https. You may refer to: About IP 0.0.0.0 in Django
In Ubuntu OS, if firewall is enabled, you need to open port 80 and 443, so that others can access your server.
In Azure portal, if NSG is enabled, you need to add inbound rules for 80 and 433.
(Optional) Buy a domain, and add an A record to your VM's IP. In this way, people would be able to access your website via friendly URL.

Redirect to an instance of Twisted web server

We have a Twisted application running as a Windows Service, serving the web application on a given port, e.g. https://localhost:8880/portal, etc. Each Windows Service is configured to serve on a particular port.
We would like to be able to redirect the request based to the right port, based on the host specified, e.g. https://bob.com/portal -> https://localhost:8880/portal.
Is this possible with tools and features available in Windows, or even with 3rd party?

How to make two different python scripts to run on the same port?

Currently I'm developing web services in python using web.py, that serves different functions. Something like
BigQueryService.py
LogicImplementer.py
PostgreService.py
Each service works perfectly when running on the local machine. After deploying on the server, due to I'm refering an other python script, it returns a module error.
Since we have to run all the services on the same port, I pasted all the scripts into a single file named Engine and made it to work using the command
$ nohup python Engine.py 8080 &
Is there any better way to structure the service in web.py? Or is there a way to run all the individual scripts on the same port?
If each service creates its own listener/server socket on the port, then the answer is no. You will need to use the equivalent of an app server that has a single server port and distributes the incoming request to the relevant app (running on the server) based typically on the relative path - so e.g. http://myserver.net:8080/bqs paths get passed to your BiqQueryService, /li to LinkImplementor, /pgs to PostgreService. Flask will do something like this, I'm sure other web service frameworks will too. The server will handle all the communication stuff, pass requests to the app (e.g. bqs) and handle sending response to the client.

Accessing Python webserver remotely on Amazon EC2

I work on a project in which I need a python web server. This project is hosted on Amazon EC2 (ubuntu).
I have made two unsuccessful attempts so far:
run python -m SimpleHTTPServer 8080. It works if I launch a browser on the EC2 instance and head to localhost:8080 or <ec2-public-IP>:8080. However I can't access the server from a browser on a remote machine (using <ec2-public-IP>:8080).
create a python class which allows me to specify both the IP address and port to serve files. Same problem as 1.
There are several questions on SO concerning Python web server on EC2, but none seems to answer my question: what should I do in order to access the python web server remotely ?
One more point: I don't want to use a Python web framework (Django or anything else): I'll use the web server to build a kind of REST API, not for serving HTML content.
you should open the 8080 port and ip limitation in security croups, such as:
All TCP TCP 0 - 65535 0.0.0.0/0
the last item means this server will accept every request from any ip and port, you also
You passble need to IAM in AWS.
Aws set security permission that need to open up port so you only localhost links your webservice
aws link

NodeJS - SocketIO over SSL with websocket transport

I have a NodeJS-socketIO server that has clients listening from JS, PHP & Python. It works like a charm when the communication happens over plain HTTP/WS channel.
Now, when i try to secure this communication, the websocket transport is not working anymore. It falls back to xhr-polling(long polling) transport. Xhr-polling still works for JS client but not on python which purely depends on socket transport.
Things i tried:
On node, Using https(with commercial certificates) instead of http - Works good for serving pages via Node but not for socketIO
Proxy via HAProxy (1.15-dev19). From HTTPS(HAProxy) to HTTP(Node). Couldn't get Websocket transport working and it falls back to xhr-polling on JS. Python gets 502 on handshake.
Proxy via STunnel (for HTTPS) -> HAProxy(Websocket Proxy) -> Node(SocketIO) - This doesnt work either. Python client still gets 502 on handshake.
Proxy via Stunnel(HTTPS) -> Node(SocketIO) - This doesnt work too. Not sure if STunnel support websocket proxy
node-http-proxy : Throws 500(An error has occurred: {"code":"ECONNRESET"}) on websocket and falls back to xhr-polling
Im sure its a common use case and there is a solution exist. Would really appreciate any help.
Thanks in advance!
My case seems to be a rare one. I built this whole environment on a EC2 instance based on Amazon Linux. As almost all the yum packages are not up to date, i had to install pretty much every yum packages from source. By doing so i could have missed configuration unchanged/added. Or HAProxy required lib could have been not the latest.
In any case, i tried building the environment again on ubuntu 12.04 based EC2 instance. HAProxy worked like a charm with a bit of configuration tweaks. I can now connect my SocketIO server from JS, Python & PHP over SSL without any problem. I could also create a Secured TCP Amazon ELB that listens on 443 and proxy it to non-standard port (8xxx).
Let me know if anyone else encounters a similar problem, I will be happy to help!

Categories

Resources