如何处理返回到 python 套接字的数据?

发布于 2024-07-26 19:26:57 字数 174 浏览 9 评论 0原文

假设您正在远程登录 IRC 以了解其工作原理。 当您发出命令时,IRC 服务器会返回数据,告诉您它正在做什么。 一旦我创建了一个默认脚本,它基本上就是服务器和客户端之间正常 IRC 连接的发生方式,如果它偏离了它,它不会告诉我出了什么问题。 我需要能够根据服务器返回给我的内容抛出异常。 我如何在 python 中做到这一点?

Say you are telneting into IRC to figure out how it all works. As you issue commands the IRC server returns data telling you what it's doing. Once I have created a default script that basically is how a normal IRC connection between server and client occurs, if it ever deviates from that it won't tell me what is wrong. I need to be able to throw exceptions based on what the server returns to me. How do I do that in python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一直都在从未离去 2024-08-02 19:26:57

下面的教程几乎引导您使用 Python 中的套接字完成 IRC 客户端:

Here's a tutorial which pretty much walks you through an IRC client using sockets in Python:

花桑 2024-08-02 19:26:57

Twisted 是一个用 Python 编写的事件驱动的网络引擎,并且包括对 IRC 协议。 要访问 IRC 功能,请将其导入:

from twisted.words.protocols import irc

请参阅示例这里:ircLogBot.py - 连接到 IRC 服务器并记录所有消息。 示例__doc__

"""An example IRC log bot - logs a channel's events to a file.

If someone says the bot's name in the channel followed by a ':',
e.g.

  <foo> logbot: hello!

    the bot will reply:

  <logbot> foo: I am a log bot

Run this script with two arguments, the channel name the bot should
connect to, and file to log to, e.g.:

  $ python ircLogBot.py test test.log

will log channel #test to the file 'test.log'.
"""

Twisted is an event-driven networking engine written in Python, and includes support for IRC protocols. To access IRC functionality, import it:

from twisted.words.protocols import irc

See an example here: ircLogBot.py - connects to an IRC server and logs all messages. The example __doc__:

"""An example IRC log bot - logs a channel's events to a file.

If someone says the bot's name in the channel followed by a ':',
e.g.

  <foo> logbot: hello!

    the bot will reply:

  <logbot> foo: I am a log bot

Run this script with two arguments, the channel name the bot should
connect to, and file to log to, e.g.:

  $ python ircLogBot.py test test.log

will log channel #test to the file 'test.log'.
"""
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文