title: Python MQTT connection to Azure Iot Hub
body: <p>I want to connect to Azure Iot Hub, with Python MQTT.</p>
  
  <p>An username and SAS token is required by Iot Hub. This is my code:</p>
  
  <pre><code>import paho.mqtt.client as mqtt
  
  def on_connect(client, userdata, flags, rc):
      print("Connected with result code "+str(rc))
      client.subscribe("$SYS/#")
  
  def on_message(client, userdata, msg):
      print(msg.topic+" "+str(msg.payload))
  
  client = mqtt.Client()
  client.on_connect = on_connect
  client.on_message = on_message
  
  client.username_pw_set("myHub.azure-devices.net/device1", "mySASToken")
  
  client.connect("myHub.azure-devices.net", 1883, 60)
  
  client.loop_forever()
  </code></pre>
  
  <p>But after running for a while, this exception is thrown:</p>
  
  <p>TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond</p>
  
  <p>Does somebody know why I can't connect to the Iot Hub?</p>