Can't subscribe to local mosquitto broker [duplicate] - python

I have a virtual machine that is supposed to be the host, which can receive and send data. The first picture is the error that I'm getting on my main machine (from which I'm trying to send data from). The second picture is the mosquitto log on my virtual machine. Also I'm using the default config, which as far as I know can't cause these problems, at least from what I have seen from other examples. I have very little understanding on how all of this works, so any help is appreciated.
What I have tried on the host machine:
Disabling Windows defender
Adding firewall rules for "mosquitto.exe"
Installing mosquitto on a linux machine

Starting with the release of Mosquitto version 2.0.0 (you are running v2.0.2) the default config will only bind to localhost as a move to a more secure default posture.
If you want to be able to access the broker from other machines you will need to explicitly edit the config files to either add a new listener that binds to the external IP address (or 0.0.0.0) or add a bind entry for the default listener.
By default it will also only allow anonymous connections (without username/password) from localhost, to allow anonymous from remote add:
allow_anonymous true
More details can be found in the 2.0 release notes here

You have to run with
mosquitto -c mosquitto.conf
mosquitto.conf, which exists in the folder same with execution file exists (C:\Program Files\mosquitto etc.), have to include following line.
listener 1883 ip_address_of_the_machine(192.168.1.1 etc.)

By default, the Mosquitto broker will only accept connections from clients on the local machine (the server hosting the broker).
Therefore, a custom configuration needs to be used with your instance of Mosquitto in order to accept connections from remote clients.
On your Windows machine, run a text editor as administrator and paste the following text:
listener 1883
allow_anonymous true
This creates a listener on port 1883 and allows anonymous connections. By default the number of connections is infinite. Save the file to "C:\Program Files\Mosquitto" using a file name with the ".conf" extension such as "your_conf_file.conf".
Open a terminal window and navigate to the mosquitto directory. Run the following command:
mosquitto -v -c your_conf_file.conf
where
-c : specify the broker config file.
-v : verbose mode - enable all logging types. This overrides
any logging options given in the config file.

I found I had to add, not only bind_address ip_address but also had to set allow_anonymous true before devices could connect successfully to MQTT. Of course I understand that a better option would be to set user and password on each device. But that's a next step after everything actually works in the minimum configuration.

For those who use mosquitto with homebrew on Mac.
Adding these two lines to /opt/homebrew/Cellar/mosquitto/2.0.15/etc/mosquitto/mosquitto.conf fixed my issue.
allow_anonymous true
listener 1883

you can run it with the included 'no-auth' config file like so:
mosquitto -c /mosquitto-no-auth.conf
I had the same problem while running it inside docker container (generated with docker-compose).
In docker-compose.yml file this is done with:
command: mosquitto -c /mosquitto-no-auth.conf

Related

How do I connect PyCharm to a remote docker registry?

I have pycharm installed on one server and have docker installed on another server.
I wish to connect PyCHarm to docker on the other server.
I have added the IP address and username and password of the server but the test connection fails.
What exactly do I enter into this configuration screen in PyCharm?
Is there a specific format of address I need to use?
Is the IP address/ address url needs to be a public one as specified here
Also keep in mind - the screen you are trying to put your details into is to add a custom docker registry details and not connect your server to another docker server. If you are trying to add a new custom registry, then great! otherwise you might want to have some ssh tunnelling to connect 2 servers.

How can one use the command-line to use openvpn on windows?

I have been trying to come up with a way to interact with openvpn on windows.
I did fine the openvpn.exe but there are no commands that will use a config file to connect with a vpn server.
I am using nordvpn by the way. Specifically a tcp Canadian server.
I did find some people suggesting to use the openvpn-gui.exe to run the program but it defeats the purpose. I want t to completely be on command line.
Secondly, i need the command line to work as i want to integrate openvopn into a script which will download stuff from the internet.
Anyone with any idea how to do it?
For anyone looking into this in 2021, please find below a connect and a disconnect.
To connect
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command connect yourconfigfile.ovpn
To disconnect
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --command disconnect yourconfigfile.ovpn
For windows users...
Both of these can be placed in a .bat file and automated with task scheduler, works like a charm.
Another CMD example:
"C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --connect config.ovpn
Replace 'config.ovpn' by your configuration file. You also may have another path to openvpn-gui.exe.
It will work if you have no openVPN correctly installed so you can't run openvpn-gui ... from cmd.
You can actually use the config file with openvpn.exe, but you must provide the full path to it unlike with openvpn-gui.exe:
openvpn.exe --config "path/to/config.ovpn"
So I figured out the answer to the problem.
To control openvpn from command-line on windows:
Set the Environment Variable so you can access the openvpn-gui.exe from command-line.
Type this command: openvpn-gui --connect [config file]. (You are going to need the config file so download it from your vpn provider)
If you don't want to type the password every time you run the script, edit the config file to read the username and password from a .txt file. Here's a link that can help you do that: https://help.vpntunnel.com/support/solutions/articles/5000613671-how-do-i-save-my-username-password-in-openvpn-for-automatic-login-
Instructions
Step 1. Go to the correct location for x64 systems:
cd "%ProgramFiles%\OpenVPN Connect"
Note: if you have the 32 bits program installed on a 64 bits OS, replace %ProgramFiles% with %ProgramFiles(x86)%.
Step 2. Install the system service:
ovpnconnector.exe install
Step 3. Specify connection profile to use (optional):
ovpnconnector.exe set-config profile <FULL_PATH_AND_FILENAME_TO_PROFILE.OVPN>
Note: if your OpenVPN Connect installation file was downloaded from Access Server or OpenVPN Cloud and came with a bundled autologin connection profile, then you can skip step 3. It will then simply default to the bundled connection profile. It can be found in the program location with the name "ovpnconnector.ovpn" - that is the bundled connection profile.
Step 4. Specify the path to a log file (optional):
ovpnconnector.exe set-config log <FULL_PATH_AND_FILENAME_TO_LOGFILE.LOG>
Note: if you skip step 4, the service will write to the default log file in the program location with the name “ovpnconnector.log”.
Step 5. Start the service:
ovpnconnector.exe start
The service will now start the VPN connection and log output to the log file.
Note: you will not receive feedback after starting the service if the connection succeeded or not. You can check the log file or use the ping command to verify that the connection is now up and running.
Important: OpenVPN Connect client should not be running, otherwise service startup will abort.

What causes the Python error in running the flask example? [duplicate]

I'm trying to create a custom TCP stack using Python 2.6.5 on Windows 7 to serve valid http page requests on port 80 locally. But, I've run into a snag with what seems like Windows 7 tightened up security. This code worked on Vista.
Here's my sample code:
import SocketServer
import struct
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
headerText = """HTTP/1.0 200 OK
Date: Fri, 31 Dec 1999 23:59:59 GMT
Content-Type: text/html
Content-Length: 1354"""
bodyText = "<html><body>some page</body></html>"
self.request.send(headerText + "\n" + bodyText)
if __name__ == "__main__":
HOST, PORT = "localhost", 80
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()
C:\python>python TestServer.py
Traceback (most recent call last):
File "TestServer.py", line 19, in
server = SocketServer.TCPServer((HOST, PORT),
MyTCPHandler) File
"C:\Python26\lib\SocketServer.py",
line 400, in init
self.server_bind() File "C:\Python26\lib\SocketServer.py",
line 411, in server_bind
self.socket.bind(self.server_address)
File "", line 1, in bind
socket.error: [Errno 10013] An attempt
was made to access a socket in a way
forbidden by its access permissions
How exactly do I get this to work on Windows 7?
[Edit on 5/5/2010 # 2344 PDT] This answer explains that the error is caused by the need for elevated / superuser privileges when accessing ports lower than 1024. I'm going to try using a higher port number to see if that works. However, I still would like to know why my local admin account can't access port 80.
I just encountered the same issue, my system is Win7. just use the command on terminal like: netstat -na|findstr port, you will see the port has been used. So if you want to start the server without this message, you can change other port that not been used.
Try to run the server at a different port. Worked for me:
python manage.py runserver 127.0.0.1:7000
Explanation:
as mentioned on Django documentation:
If you run this script as a user with normal privileges (recommended), you might not have access to start a port on a low port number. Low port numbers are reserved for the superuser (root).
This server uses the WSGI application object specified by the WSGI_APPLICATION setting.
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
On Windows Vista/7, with UAC, administrator accounts run programs in unprivileged mode by default.
Programs must prompt for administrator access before they run as administrator, with the ever-so-familiar UAC dialog. Since Python scripts aren't directly executable, there's no "Run as Administrator" context menu option.
It's possible to use ctypes.windll.shell32.IsUserAnAdmin() to detect whether the script has admin access, and ShellExecuteEx with the 'runas' verb on python.exe, with sys.argv[0] as a parameter to prompt the UAC dialog if needed.
For me it was complaining like that on Windows 7 x64 when I had another process already listening on that same port.
It is possible to see currently occupied (bound) ports by running
netstat -ban
McAfee was blocking it for me. I had to allow the program in the access protection rules
Open VirusScan
Right click on Access Protection and choose Properties
Click on "Anti-virus Standard Protection"
Select rule "Prevent mass mailing worms from sending mail" and click edit
Add the application to the Processes to exclude list and click OK
See http://www.symantec.com/connect/articles/we-are-unable-send-your-email-caused-mcafee
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Got this with flask :
Means that the port you're trying to bind to, is already in used by another service or process :
got a hint on this in my code developed on Eclipse / windows :
if __name__ == "__main__":
# Check the System Type before to decide to bind
# If the system is a Linux machine -:)
if platform.system() == "Linux":
app.run(host='0.0.0.0',port=5000, debug=True)
# If the system is a windows /!\ Change /!\ the /!\ Port
elif platform.system() == "Windows":
app.run(host='0.0.0.0',port=50000, debug=True)
Your local port is using by another app. I faced the same problem!
You can try the following step:
Go to command line and run it as administrator!
Type:
netstat -ano | find ":5000"
=> TCP 0.0.0.0:5000 0.0.0.0:0 LISTENING 4032
TCP [::]:5000 [::]:0 LISTENING 4032
Type:
TASKKILL /F /PID 4032
=> SUCCESS: The process with PID 4032 has been terminated.
Note: My 5000 local port was listing by PID 4032. You should give yours!
Just run on ports above 1024 , anything below is privileged, its the same deal with Linux, i use 5000 for example on wins without any UAC priv escalation.
It Seems the Port 80 is already in use. Try to Use some other Port which is not in use by any other application in your System.
I solved this on Windows 10 by editing an outbound firewall rule.
Right click "allow" on rule "Block network access for R local user accounts in SQL Server instance MSSQLSERVER"
Screenshot from Windows 10 Firewall - Outbound rules- this is what was blocking my instance
I had to allow ..\python27\python.exe in windows firewall. I don't need to do this on WinXP or Win8.
Try using a different port than 80
The main problem is port number used by another application.So you can change the port number to unused one as shown below.
In windows you can view the used port numbers used by different apps in windows task manager.
python manage.py runserver 127.0.0.1:portnumber
Ex: python manage.py runserver 127.0.0.1:8080
I just found in my case Kaspersky Internet Security 2019 Firewall was blocking net access for python. Disabling firewall working smoothly. Or adding a exception rules for python app and all file extension with *.py will also work.
Here is a simple solution to your problem..this error occurs either due to another process or bunch of processes running on the port which you are trying to run you app on.
Open cmd as an admin
This may also occure if you have setup your server as a SERVICE and the service breaks.
Give below command
netstat -ano | findstr portNo
you'll be able to see list of active task on that port.
you can close all unnecessary task by using
taskkill/pid taskNo /F
once done restart your server.
Disable Access Protection in Antivirus,
I faced same issue at last found the below logs from antivirus.
Blocked by Access Protection rule NT AUTHORITY\SYSTEM C:\WINDOWS\SYSTEM32\SVCHOST.EXE C:\PROGRAM FILES (X86)\MCAFEE\VIRUSSCAN ENTERPRISE\MCCONSOL.EXE Common Standard Protection:Prevent termination of McAfee processes Action blocked : Terminate
Blocked by port blocking rule C:\USERS\username\APPDATA\LOCAL\PROGRAMS\PYTHON\PYTHON37-32\PYTHON.EXE Anti-virus Standard Protection:Prevent mass mailing worms from sending mail
In Windows check "World Wide Web Publishing Service" if it is running, because when you install IIS it has a service that auto. starts and listens 80, 443 port.
netstat -ano | find ":80"
then TASKKILL /F /PID 4032
as rafee noor said, but this doesn't work when Port is being used by SYSTEM
Port 80 is being used by SYSTEM (PID 4), what is that?
or
NET stop HTTP
this works in above case
I found a solution to solve this problem in Python.
go to c:\python27\ directory and rigtlcick python.exe and tab to compaitbility and select the admin privilege option and apply the changes. Now you issue the command it allows to create the socket connection.

Can't access app deployed with docker and google cloud

I currently have a Linux Debian VM set up through Google Cloud Platform. I have docker installed and would like to start running application containers within it.
I'm following the documentation under Docker's website Found Here under
"Running a web application in Docker" I download the image and run it with no issue. I then run $sudo docker ps and get the port which is 0.0.0.0:32768->5000/tcp
I then try to browse to the website at http://"MyExternalVMIP":32768 but the applications doesn't come up. Am I missing something?
First, test to see if your service works at all. To do this, from the VM itself, run:
wget http://localhost:32768
or
curl http://localhost:32768
If that works, that means the service is operating properly, so let's move further with the debugging.
There may be two firewalls that are blocking external access to your docker process:
the VM's OS firewall
Google Compute Engine firewall
You can see if you're affected by the first issue by accessing the URL from the VM itself and from another VM on the same GCE network (use the VM name in the URL, not the external IP):
wget http://[vm-name]:32768
To fix the first issue, you would have to either open up the single port (recommended):
iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 32768 -j ACCEPT
or disable firewall entirely, e.g., by stopping iptables (not recommended).
If, after fixing this, you can access the URL from another host on the same GCE network, but still can't access it from outside of Google Compute Engine, you're affected by the second issue. To fix it, you will need to open the port in the GCE firewall; this can also be done via the web UI in the Developers Console.
Create an entry in your local ssh config file as below with specific local forward port. In my case its an example of yarn's IP, which I want to access in browser.
Host hadoop
HostName <External-IP>
User <Local-machine-username>
IdentityFile ~/.ssh/<private-key-for-above-user>
LocalForward 8089 <Internal-IP>:8088

Python process suspends on SSH logout after nohup/screen

I have a remote server through Blue Host that's intended to run a server based on Twisted for Python. The only access I have to it is over SSH, so to keep Python running after I log out I tried using nohup python server.py & and screen -dm python server.py, getting the same results for each. Everything works fine until I log out of SSH - even though Python is running in the background as expected, once I've logged out, my client can no longer communicate with the server. The strange part is that if I log back in over SSH and check the running processes with ps aux, I see Python running and my client can successfully communicate with the server again. Even if I don't type anything at all once I log back in, everything works as expected. But, of course, as soon as I log back out, it's as if the server is gone.
I've contacted support for the hosting service in case this is some oddity on their end, but hopefully this is something that can be resolved on my end instead.
Edit: Looks like Blue Host doesn't want me doing server-y stuff without buying the VPS upgrade so it looks like that's the big problem.
Edit 2: Okay, so in case anybody ends up having a similar problem, here's what the main issue turned out to be. I was mistaken in my original description; I was able to connect to the server but I was getting kicked off immediately for what turned out to be a MySQL error. I guess trying to connect to a localhost database with no active connection somehow causes problems, so instead I changed the MySQL connection command to connect to my site's IP address instead, even though it was the same IP as the server. That seemed to do the trick in terms of my main issue.
Don't use this method to keep the server process running. Instead try using supervisor (apt-get install supervisor). It allows you to daemonize your process, and ability to stop/restart etc.
Here's a sample config entry (/etc/supervisor/supervisord.conf):
[program:my_server]
command=python /path/to/server/server.py
directory=/path/to/server/
autostart=true
autorestart=true
stdout_logfile=/var/log/server.log
stderr_logfile=/var/log/server_error.log
user=your_linux_user_name
After you edit your config, do
sudo service supervisor stop
sudo service supervisor start #need to do this - doing a `restart` doesn't reload the config file!
your server should now be running properly. You can manage its lifecycle via sudo supervisorctl

Categories

Resources