Comments (6)
Because IRC is asynchronous, I believe it needs a handler for whatever response might be given by the server. I'm not familiar with the protocol, but what I suspect is that you'll need add a global handler to the client for an appropriate event, and when the event comes in that indicates a bad password, you can handle that however is appropriate (disconnect, prompt, re-try, etc).
Original comment by: Jason R. Coombs
from irc.
What would really help here is more detail about what a server does (either according to the spec or inferred from actual behavior) in the case of an invalid password. You can probably run the client with debug logging enabled against a server where you transmit an invalid password. That will provide a better indication of what response might be handled by the client.
Original comment by: Jason R. Coombs
from irc.
All great points. Thanks to your input I believe I have a plan to move forward. Thanks!
Original comment by: Brendan Ashby
from irc.
On further consideration, I suspect the client should probably raise an error if it attempts to send a password which is rejected by the server. I wonder if the server always sends a response to a PASS command, only only when it's invalid. If only the latter, then it'll be harder to detect an error condition.
I'd be interested to hear what you've encountered regarding this issue.
Original comment by: Jason R. Coombs
from irc.
After looking into this more, I'm a little frustrated with the way the library handles errors. Using a server my company has, which also requires a password, I attempted to connect using an invalid password with this script:
import logging
import ssl
logging.basicConfig(level=logging.DEBUG)
import irc.client
import irc.connection
client = irc.client.IRC()
server = client.server()
password = 'foo'
ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
conn = server.connect(
'irc.example.net', 7000, 'jaraco_test',
password=password,
connect_factory=ssl_factory,
)
def on_error(connection, event):
print(event.target)
if 'Password mismatch' in event.target:
connection.disconnect("You can't fire me; I quit!")
raise Exception("Failed to authenticate")
client.add_global_handler('error', on_error)
client.process_forever()
(I've replaced our actual server and port)
What I get if I run that is this:
> python .\bad-pass.py
DEBUG:irc.client:connect(server='irc.example.com', port=7000, nickname='jaraco_test', ...)
DEBUG:irc.client:TO SERVER: PASS foo
DEBUG:irc.client:TO SERVER: NICK jaraco_test
DEBUG:irc.client:TO SERVER: USER jaraco_test 0 * :jaraco_test
DEBUG:irc.client:process_forever(timeout=0.2)
DEBUG:irc.client:FROM SERVER: :irc.example.com NOTICE AUTH :*** Looking up your hostname...
DEBUG:irc.client:command: privnotice, source: irc.example.com, target: AUTH, arguments: ['*** Looking up your hostname...']
DEBUG:irc.client:FROM SERVER: :irc.example.com NOTICE AUTH :*** Found your hostname
DEBUG:irc.client:command: privnotice, source: irc.example.com, target: AUTH, arguments: ['*** Found your hostname']
DEBUG:irc.client:FROM SERVER: ERROR :Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch)
DEBUG:irc.client:command: error, source: None, target: Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch), arguments: []
Closing Link: jaraco_test[c-68-55-72-219.hsd1.dc.comcast.net] (Password mismatch)
DEBUG:irc.client:TO SERVER: QUIT :You can't fire me; I quit!
Traceback (most recent call last):
File ".\bad-pass.py", line 26, in <module>
client.process_forever()
File "C:\Users\jaraco\projects\irc\irc\client.py", line 266, in process_forever
self.process_once(timeout)
File "C:\Users\jaraco\projects\irc\irc\client.py", line 247, in process_once
self.process_data(i)
File "C:\Users\jaraco\projects\irc\irc\client.py", line 212, in process_data
c.process_data()
File "C:\Users\jaraco\projects\irc\irc\client.py", line 645, in process_data
self._handle_event(Event(command, NickMask(prefix), target, arguments))
File "C:\Users\jaraco\projects\irc\irc\client.py", line 649, in _handle_event
self.irclibobj._handle_event(self, event)
File "C:\Users\jaraco\projects\irc\irc\client.py", line 386, in _handle_event
result = handler.callback(connection, event)
File ".\bad-pass.py", line 23, in on_error
raise Exception("Failed to authenticate")
Exception: Failed to authenticate
But more interestingly, if I leave out the 'raise Exception' clause, the script will run indefinitely. It will 'process_forever' even though it'll never have any sockets in the main event loop.
So a few things to note. First, the IRC library could probably handle better the circumstance where it doesn't have any connections. Second, the IRC server we use doesn't follow the RFC for handling the invalid password. Third, it was fairly straightforward to write a handler to capture when the password is invalid.
I realize this doesn't "fix" the issue, but it should help anyone struggling with it to better understand how to handle it.
Original comment by: Jason R. Coombs
from irc.
I'm going to close this as wontfix for now. If someone wishes to provide a session (perhaps using the script above) to show a transcript of a session against a server that follows the RFC for bad passwords, please do so, and I will gladly add support for the library.
As it is, the one example I have is a non-compliant example, so probably belongs in custom code and not in the library.
Original comment by: Jason R. Coombs
from irc.
Related Issues (20)
- How to cleanly stop a reactor? HOT 2
- why do I get this error when using Pidgin client for connecting to IRC? ERROR :Closing Link: c-66-31-107-137.hsd1.ma.comcast.net (*** Banned ) HOT 1
- How to get connection log? HOT 3
- Add example on how to send a message to a channel HOT 1
- How can i print irc messages in my console?
- Disconnect issue HOT 1
- Implement default handler if nothing matches HOT 1
- [AIO] No client side ping-pong
- [AIO] Excess flood prevention HOT 3
- [AIO] Registering a connection needs to be split out of connect() HOT 1
- [AIO] Connection real_nickname must not be set before registration HOT 1
- [AIO] Implement SASL PLAIN with expect() flow
- High CPU usage in irc.server. HOT 1
- Add support for ignoring ssl validation in the examples HOT 2
- Add support for SASL HOT 4
- In tests DeprecationWarning no event loop
- ValueError when trying to download using DCC HOT 2
- Basic irc bot HOT 1
- DCC Transfers getting stuck HOT 1
- Test regressions: irc/dict.py::irc.dict.IRCDict, irc/strings.py::irc.strings.IRCFoldedCase
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from irc.