python xmpp simple client error - python

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.

Related

Receive data from a client/server doesn't work

I developed a small Python program which should receive and output data from another client or server. However, I get an error message which is unknown to me. Can anyone help me? Thanks a lot
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('192.168.1.34', 80))
from_server = client.recv(4096)
client.close()
print from_server
Error:
Traceback (most recent call last):
File "CallManager2.py", line 4, in <module>
client.connect(('192.168.1.34', 80))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
The error comes from inability for your program to reach the server or other client.
Check that there is something listening to incoming connexions on the address you want to connect to.
Then you can check that the address you want to connect to is on the same network as your program.

Can not get remote access to RabbitMq server

I can't get remote access to the RabbitMq server. When I am doing this at one machine and connect to localhost:15672 it works, but when I try from a remote machine it's not.
I have already created a user with all permissions and check that 5672 port on computer works (just tried to connect to him from a remote computer). Also, I tried to connect to 15672 port, but no result.
credentials = pika.PlainCredentials(username= 'username', password='password')
parameters = pika.ConnectionParameters(host='188.19.100.226',
port=5672,
virtual_host= '/',
credentials=credentials)
connection = pika.BlockingConnection(parameters=parameters)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body=hello)
print ("Sent!")
connection.close()
I expect to see Sent!, but instead of I get:
ERROR:pika.adapters.utils.io_services_utils:Socket failed to connect: <socket.socket fd=7, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('192.168.100.2', 44752)>; error=111 (Connection refused)
ERROR:pika.adapters.utils.connection_workflow:TCP Connection attempt failed: ConnectionRefusedError(111, 'Connection refused'); dest=(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('188.19.100.226', 5672))
ERROR:pika.adapters.utils.connection_workflow:AMQPConnector - reporting failure: AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused')
ERROR:pika.adapters.utils.connection_workflow:AMQP connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None.
ERROR:pika.adapters.utils.connection_workflow:AMQPConnectionWorkflow - reporting failure: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None
ERROR:pika.adapters.blocking_connection:Connection workflow failed: AMQPConnectionWorkflowFailed: 1 exceptions in all; last exception - AMQPConnectorSocketConnectError: ConnectionRefusedError(111, 'Connection refused'); first exception - None
ERROR:pika.adapters.blocking_connection:Error in _create_connection().
Traceback (most recent call last):
File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
Traceback (most recent call last):
File "/home/roman/PycharmProjects/trrp2/send.py", line 52, in <module>
connection = pika.BlockingConnection(parameters=parameters)
File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 359, in __init__
self._impl = self._create_connection(parameters, _impl_class)
File "/home/roman/PycharmProjects/trrp2/venv/lib/python3.6/site-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
You need to configure rabbitmq to listen to other interfaces than local host.
To accept connections from all interfaces, listen to 0.0.0.0
https://www.rabbitmq.com/networking.html#interfaces

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}

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 Connection with mongoHQ fails?

I want to connect to mongoHq database through python.
here is what i have done so far
an environmental variable is set:
MONGOHQ_URL = mongodb://myusername:mypassword#paulo.mongohq.com:10084/mydb
and the app.py file
import os
import datetime
import pymongo
from pymongo import MongoClient
MONGO_URL = os.environ.get('MONGOHQ_URL')
client = MongoClient(MONGO_URL)
db = client.mydb
when i run this file following error comes
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win-amd64.egg\pymongo\mongo_client.py", line 349, in __init__
self.__find_node(seeds)
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win-amd64.egg\pymongo\mongo_client.py", line 750, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:27017: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python33\flaskk\test.py", line 9, in <module>
client = MongoClient(MONGO_URL)
File "C:\Python33\lib\site-packages\pymongo-2.6.2-py3.3-win- amd64.egg\pymongo\mongo_client.py", line 352, in __init__
raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: could not connect to localhost:27017: [WinError 10061]
No connection could be made because the target machine actively refused it
Please help !! Thanks in advance !!
I think , there is no need of setting environment variable for testing it in local machine , and maybe the error is because it didn't get set properly.
Another issue I can see , that you haven't replaced user and pass with your username password of user you created for particular database.Try connecting your mongo shell with that monhqurl by typing
mongo --username <user> --password <pass> --host <host> --port 28015
replacing it with your details .If it connects successfully then mongohqurl is correct

Categories