Slack bot rtm connect fails behind proxy, using python slackclient - python

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}

Related

Azure IoT client not getting connected to IoT Hub

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.

raise SlackLoginError(reply=reply) slackclient.server.SlackLoginError

Running the below small script passing OAuth Access Token as a token here :
from slackclient import SlackClient
import os
token = "*********"
sc = SlackClient(token)
print (sc.api_call("api.test"))
if sc.rtm_connect():
print("Starter Bot connected and running!")
GETTING BELOW ERROR
Failed RTM connect
Traceback (most recent call last):
File "C:\Users\320055379\AppData\Local\Programs\Python\Python38-32\lib\site-packages\slackclient\client.py", line 140, in rtm_connect
self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
File "C:\Users\320055379\AppData\Local\Programs\Python\Python38-32\lib\site-packages\slackclient\server.py", line 168, in rtm_connect
raise SlackLoginError(reply=reply)
slackclient.server.SlackLoginError
the new granual scope does not support rtm anymore, you can try this link to create a classic bot https://api.slack.com/rtm#create_a_classic_slack_app

Catching Firebase 504 gateway timeout

I'm building a simple IOT device (with a Raspberry Pi Zero) which pulls data from Firebase Realtime Database every 1 second and checks for updates.
However, after a certain time (not sure exactly how much but somewhere between 1 hour and 3 hours) the program exits with a 504 Server Error: Gateway Time-out message.
I couldn't understand exactly why this is happening, I tried to recreate this error by disconnecting the Pi from the internet and I did not get this message. Instead, the program simply paused in a ref.get() line and automatically resumed running once the connection was back.
This device is meant to be always on, so ideally if I get some kind of error, I would like to restart the program / reinitiate the connection / reboot the Pi. Is there a way to achieve something like this?
It seems like the message is actually generated by the firebase_admin package.
Here is the error message:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 944, in request
return super(_Client, self).request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 105, in request
resp.raise_for_status()
File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://someFirebaseProject.firebaseio.com/someRef/subSomeRef/payload.json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/project/main.py", line 94, in <module>
lastUpdate = ref.get()['lastUpdate']
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 223, in get
return self._client.body('get', self._add_suffix(), params=params)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/_http_client.py", line 117, in body
resp = self.request(method, url, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/db.py", line 946, in request
raise _Client.handle_rtdb_error(error)
firebase_admin.exceptions.UnknownError: Internal server error.
>>>
To reboot the whole Raspberry Pi, you can just run a shell command:
import os
os.system("sudo reboot")
I've had this problem too and usually feel safer with that, but there's obvious downsides. I'd try resetting the wifi connection or network interface in a similar way

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 ?

python xmpp simple client error

I'm getting the following error:
AttributeError: Client instance has no attribute 'Dispatcher'
while running the following code in python 2.7:
import xmpp
user= 'uname#gmail.com'
password="pass"
jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain())
connection.connect()
connection.auth(jid.getNode(),password)
Would be happy if someone knows how to fix it.
P.S. Full traceback of the error after the fix proposed by N3RO:
C:\Users\krasnovi\Desktop\temp\xmpp tests>python xmpp.client.py
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027C1708> into <xmpp.client.Client instance at 0x00000000027C1588>
DEBUG: socket warn An error occurred while looking up _xmpp-client._tcp.t
alk.gmail.com
DEBUG: socket error Failed to connect to remote host ('talk.gmail.com', 52
23): getaddrinfo failed (11004)
Traceback (most recent call last):
File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect
self._sock.connect((server[0], int(server[1])))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
gaierror: [Errno 11004] getaddrinfo failed
DEBUG: socket stop Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027C1708> out of <xmpp.client.Client instance at 0x00000000027C1588>.
Traceback (most recent call last):
File "xmpp.client.py", line 11, in <module>
connection.auth(jid.getNode(),password)
File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth
AttributeError: Client instance has no attribute 'Dispatcher'
Before the fix:
Invalid debugflag given: always
Invalid debugflag given: nodebuilder
DEBUG:
DEBUG: Debug created for build\bdist.win-amd64\egg\xmpp\client.py
DEBUG: flags defined: always,nodebuilder
DEBUG: socket start Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027ED708> into <xmpp.client.Client instance at 0x00000000027ED588>
DEBUG: socket error Failed to connect to remote host ('xmpp.l.google.com.'
, 5222): A connection attempt failed because the connected party did not properl
y respond after a period of time, or established connection failed because conne
cted host has failed to respond (10060)
Traceback (most recent call last):
File "build\bdist.win-amd64\egg\xmpp\transports.py", line 133, in connect
self._sock.connect((server[0], int(server[1])))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10060] A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection failed b
ecause connected host has failed to respond
DEBUG: socket stop Plugging <xmpp.transports.TCPsocket instance at 0x0000
0000027ED708> out of <xmpp.client.Client instance at 0x00000000027ED588>.
Traceback (most recent call last):
File "xmpp.client.py", line 11, in <module>
connection.auth(jid.getNode(),password)
File "build\bdist.win-amd64\egg\xmpp\client.py", line 214, in auth
AttributeError: Client instance has no attribute 'Dispatcher'
You need to specify a server you want to connect to.
connection.connect(server=('serveradress.com', portnumber))
After changing this I couldn't reproduce the AttributeError.
I would also advise you to use a correct JID to test your code.
JID's are like E-Mails separated by an #, which is why in your sample code jid.getNode() returns nothing.
*Edit my Code example:
import xmpp
user = 'username#gmail.com'
password = 'password'
jid = xmpp.JID(user)
connection = xmpp.Client(jid.getDomain())
connection.connect(server=('talk.google.com', 5223))
connection.auth(jid.getNode(), password)
connection.sendInitPresence()
In your traceback it looks like you are trying to connect to talk.gmail.com which is a non existant domain, so the connection.connect statement will fail to open a connection.
Try to connect to talk.google.com which may be the right server's name.

Categories