Azure IoT client not getting connected to IoT Hub - python

Im facing these errors in my Invoke Module.
I have two modules which runs python script. One module to get invoked cloud message and other to receive the invoked cloud message through the input.
Everything was working fine and suddenly Im receiving:
FYI: The python script with my updated changes is working fine when I commit changes after entering into the container(which has my previously successfully build and deployed version of module), but when I deploy the module through the deployment manifest its failing with these errors.
Connected with result code 0
transport.connect raised error
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 383, in connect
host=self._hostname, port=8883, keepalive=DEFAULT_KEEPALIVE
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 937, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1071, in reconnect
sock = self._create_socket_connection()
File "/usr/local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
File "/usr/local/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/lib/python3.7/socket.py", line 752, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/pipeline/pipeline_stages_mqtt.py", line 168, in _run_op
self.transport.connect(password=self.sas_token)
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 405, in connect
raise exceptions.ConnectionFailedError(cause=e)
azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
ConnectOperation: completing with error ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
ConnectionLockStage(ConnectOperation): op failed. Unblocking queue with error: ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
ConnectOperation: completing with error ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
Callback completed with error ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')
["azure.iot.device.common.transport_exceptions.ConnectionFailedError: ConnectionFailedError(None) caused by gaierror(-2, 'Name or service not known')\n"]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/azure/iot/device/common/mqtt_transport.py", line 383, in connect
host=self._hostname, port=8883, keepalive=DEFAULT_KEEPALIVE
Im using azure-iot-device = 2.1.1.
Please help me with suggestion to resolve this.

I have faced a similar issue and I resolved it using the following.
Please check if you have mentioned
NetworkMode = "Hosts" in your deployment.json
If yes then remove it and it works just fine

A cursory scan of the stack suggests you might have a DNS problem. It appears unable to resolve the host name. That is what getaddrinfo is attempting to do. You don't mention what type of device this is but, if you have ping available try using it to ping your IoT hub. It won't respond to the ping but it will tell you if it was able to resolve the name.

Related

Quickstart.py - failed to connect to all addresses

I installed the Python libraries on my local PC, I also added my GA-4 Property ID. When I attempt to run the script I get the following error, note that the error actually makes sense because the IP Address failing doesn't have a valid SSL certificate:
Traceback (most recent call last):
File "\\usalbodd01\bod_Share\BODS_Tools\google\api_core\grpc_helpers.py", line 72, in error_remapped_callable
return callable_(*args, **kwargs)
File "\\usalbodd01\bod_Share\BODS_Tools\grpc\_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "\\usalbodd01\bod_Share\BODS_Tools\grpc\_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:142.250.190.10:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED"
debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:142.250.190.10:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED {grpc_status:14, created_time:"2022-11-28T18:41:22.060505311+00:00"}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "\\usalbodd01\bod_Share\BODS_Tools\GoogleQuickstart.py", line 51, in <module>
sample_run_report("")
File "\\usalbodd01\bod_Share\BODS_Tools\GoogleQuickstart.py", line 43, in sample_run_report
response = client.run_report(request)
File "\\usalbodd01\bod_Share\BODS_Tools\google\analytics\data_v1beta\services\beta_analytics_data\client.py", line 511, in run_report
response = rpc(
File "\\usalbodd01\bod_Share\BODS_Tools\google\api_core\gapic_v1\method.py", line 154, in __call__
return wrapped_func(*args, **kwargs)
File "\\usalbodd01\bod_Share\BODS_Tools\google\api_core\grpc_helpers.py", line 74, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:142.250.190.10:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
Have any of you run into this when attempting to run the quickstart.py script locally?
Regards,
Greg
I attempted to run the script after following the "TODOS". I installed the Google certificates locally. I then tested the IP Address the script is failing on, the address is not secured.
Your connection isn't private
Attackers might be trying to steal your information from 142.250.190.10 (for example, passwords, messages, or credit cards).
NET::ERR_CERT_AUTHORITY_INVALID

Python myqsl.connector connection error on pyton.org

I have a mysql server on my computer. I did port fowarding on my modem. I checked port is open or not with signal sites and return success answer. When i try connect on my pc with host = "localhost" i returned success answer. But when i try connect mysql server with python.org's shell, i returned connection error same like this:
Traceback (most recent call last):
File “/usr/lib/python3.8/site-packages/mysql/connector/network.py”, line 529, in open_connection
self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python3.8/site-packages/mysql/connector/init.py”, line 177, in connect
return MySQLConnection(*args, **kwargs)
File “/usr/lib/python3.8/site-packages/mysql/connector/connection.py”, line 104, in init
self.connect(**kwargs)
File “/usr/lib/python3.8/site-packages/mysql/connector/abstracts.py”, line 781, in connect
self._open_connection()
File “/usr/lib/python3.8/site-packages/mysql/connector/connection.py”, line 284, in _open_connection
self._socket.open_connection()
File “/usr/lib/python3.8/site-packages/mysql/connector/network.py”, line 531, in open_connection
raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can’t connect to MySQL server on ‘myipadress:3306’ (111 Con
nection refused)
How can i connect my mysql server ?
In order to encounter this error first do the following:
Make sure the host is in the format 127.0.0.1 and there are no / or \ in the host name
Check if you have specified all the correct info about the server like passwords, user, root, etc
Make sure the server is active and there is no fire wall blocking your access
Remove all the unwanted users from the server

Slack bot rtm connect fails behind proxy, using python slackclient

When running slack bot using proxies SlackClient.rtm_connect() fails with below error, where as at the same time api_calls api.test, auth.test seems working fine, any idea how this can be fixed ? Am i missing some other configuration ?
WARNING:slackclient.client:Failed RTM connect
Connection failed. Exception traceback printed above.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "C:\Python27\lib\site-packages\slackclient\server.py", line 159, in rtm_connect
self.connect_slack_websocket(self.ws_url)
File "C:\Python27\lib\site-packages\slackclient\server.py", line 200, in connect_slack_websocket
raise SlackConnectionError(message=str(e))
SlackConnectionError: [Errno 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
Below is the code snippet,
from slackclient import SlackClient
client_proxies = {"https": "https://127.0.0.1:8080"}
slack_client = SlackClient(token=BOT_TOKEN, proxies=client_proxies)
print slack_client.api_call("api.test")
print slack_client.api_call("auth.test")
slack_client.rtm_connect()
api_call api.test returned below
{u'token': u'TOKEN'}, u'ok': True}

I don't know why but this code sometimes works and sometimes throws an error any idea? :

I've this code that publishes multiple messages to different topics.
"""
Publish some messages to queue
"""
import paho.mqtt.publish as publish
host ="test.mosquitto.org"
msgs = [{'topic': "A/A1", 'payload': "30"},
{'topic': "A/A2", 'payload': "40"},
{'topic': "A/A3", 'payload': "1"}]
if __name__ == '__main__':
# publish multiple messages
publish.multiple(msgs, hostname=host)
but some times it works for me and publishes the data and sometimes it throws this error.
Traceback (most recent call last):
File "/home/pi/Desktop/NRF24L01/publish.py", line 22, in <module>
publish.multiple(msgs, hostname=host)
File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/publish.py", line 159, in multiple
client.connect(hostname, port, keepalive)
File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
return self.reconnect()
File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python3.5/socket.py", line 693, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] **Temporary failure in name resolution**
after a lot of research I saw some comments saying it's DNS problem or the proxy is closed but couldn't solve in anyway. please any one who can help me?
Thanks in advance.
The important part of the error is here:
socket.gaierror: [Errno -3] **Temporary failure in name resolution**
This means that the Raspberry Pi that you are running the code in could not find the IP address for test.mosquitto.org.
This most likely means that there is nothing wrong with the code you have, but you need to look at how the Raspberry Pi is connecting to the internet.
It could be any number of issues but some of them could be:
A weak WiFi connection
A faulty Broadband connection
A problem at your ISP
Unfortunately there isn't really any way we can know what it is remotely.

Why is this MQTT client example failing?

I am trying out MQTT for the first time using Python and the mosquitto library. My client program is below. I'm trying to use the public demo MQTT server at http://www.mqtt-dashboard.com/subscribe. However the client code is failing, see error below. Any ideas on what's going on?
#!/usr/bin/env python
import mosquitto
client = mosquitto.Mosquitto("fredtest", clean_session=True)
client.connect("broker.mqttdashboard.com", 1883)
client.publish("fred.test", "hello world", 1)
client.loop_forever()
Error message:
C:\tmp>python mqttclient.py
Traceback (most recent call last):
File "mqttclient.py", line 6, in
client.connect("broker.mqttdashboard.com", 1883)
File "build\bdist.win-amd64\egg\mosquitto.py", line 582, in connect
File "build\bdist.win-amd64\egg\mosquitto.py", line 657, in reconnect
File "c:\python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10060] A connection attempt failed because the connected pa
rty did not properly respond after a period of time, or established connection f
ailed because connected host has failed to respond
I'm not currently able to connect any client to broker.mqttdashboard.com:1883 - so this probably isn't an issue with your code.
To sanity check, have you tried connected to another broker, such as iot.eclipse.org:1883 ?

Categories