PythonAnywhere Forums

CloudMQTT Connection Refused

Hello! I am a complete beginner with pythonanywhere (and kind of with python, too). I am working on a Internet of Things group project at school and I was thinking about using pythonanywhere as a server kind of thing that could take messages from my CloudMQTT message queue (that is already working) and make JSON out of them and save them to a database/file.

Maybe it is a stupid approach, we are learning ))

Anyways, I uploaded my python script (that connects to the MQTT queue) on pythonanywhere, installed and imported the paho.mqtt.client library (successfully) but when I run the script, it gives an error message:

13:53 ~ $ python2.7 mqtt.py
Traceback (most recent call last):                                                                                                                          
  File "mqtt.py", line 37, in <module>                                                                                                                      
    mqttc.connect("m20.cloudmqtt.com", "36348")                                                                                                             
  File "/home/PetrKryze/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 768, in connect                                                       
    return self.reconnect()                                                                                                                                 
  File "/home/PetrKryze/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 895, in reconnect                                                     
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))                                                       
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection                                                                                       
    raise err                                                                                                                                               
socket.error: [Errno 111] Connection refused

Could anyone help or give some tips? Thanks alot!

For free accounts making outbound connections, you can only make http/https connections to a whitelist.

So just upgrading the account will solve the problem? Thanks

Yes, it will

Hi, I have had the same problem using mqtt as a client and have upgraded to a paid account and I still get the connection refused error.

File "Upload_ttn-sub-temp.py", line 72, in <module> client.connect(TTN_SERVER, keepalive=30) File "/home/paulneumeyer/.virtualenvs/loraenv/lib/python3.6/site-packages/paho/mqtt/client.py", line 768, in connect return self.reconnect() File "/home/paulneumeyer/.virtualenvs/loraenv/lib/python3.6/site-packages/paho/mqtt/client.py", line 895, in reconnect sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0)) File "/usr/lib/python3.6/socket.py", line 722, in create_connection raise err File "/usr/lib/python3.6/socket.py", line 713, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

What is the expected delay from payment to the ports being open?

I'm not sure if the only way to getting it running is in a Web application. I run the script from a Bash console and it fails. I run the same virtualenv from a Web application and run the same script and it runs.

Do I need to recreate the bash console now I have paid?

yes, you need a new Bash console to get the updated Internet settings. I think we say as much on the final upgrade screen...