使用Scrapy v1.5.1时,我能够使用telnetlib远程登录到正在运行的Scrapy作业:
In [62]: import logging
...: from telnetlib import Telnet
...:
...: tn = Telnet('127.0.0.1', 6024, timeout=10)
...: tn.set_debuglevel(logging.DEBUG)
...:
...: tn.write(b'settings.attributes["BOT_NAME"]\n')
...: tn.read_until(b'\n>>>', timeout=10)
Telnet(127.0.0.1,6024): send b'settings.attributes["BOT_NAME"]\n'
Telnet(127.0.0.1,6024): recv b'\xff\xfd"\xff\xfd\x1f\xff\xfd\x03\xff\xfb\x01\x1bc>>> \x1b[4hsettings.attributes["BOT_NAM'
Telnet(127.0.0.1,6024): IAC DO 34
Telnet(127.0.0.1,6024): IAC DO 31
Telnet(127.0.0.1,6024): IAC DO 3
Telnet(127.0.0.1,6024): IAC WILL 1
Telnet(127.0.0.1,6024): recv b'E"]\r\r\r\n<SettingsAttribute value=\'demo\' priority=20'
Telnet(127.0.0.1,6024): recv b'>\r\r\r\n>>> '
Out[62]: b'\x1bc>>> \x1b[4hsettings.attributes["BOT_NAME"]\r\r\r\n<SettingsAttribute value=\'demo\' priority=20>\r\r\r\n>>>'
但是从v1.5.2开始,Scrapy的telnet控制台现在需要用户名和密码。而且我能够使用Win7上的telnet客户端telnet到正在运行的作业,但使用telnetlib失败:
In [36]: tn = Telnet('127.0.0.1', 6023, timeout=10)
In [37]: tn.set_debuglevel(logging.DEBUG)
In [38]: tn.read_until(b'Username: ', timeout=10)
Telnet(127.0.0.1,6023): recv b'Username: '
Out[38]: b'Username: '
In [39]: tn.write(b'scrapy\n')
Telnet(127.0.0.1,6023): send b'scrapy\n'
In [40]: tn.read_until(b'Password: ', timeout=10)
Telnet(127.0.0.1,6023): recv b'\xff\xfb\x01Password: '
Telnet(127.0.0.1,6023): IAC WILL 1
Out[40]: b'Password: '
In [41]: tn.write(b'f5e435eb420c32cd\n')
Telnet(127.0.0.1,6023): send b'f5e435eb420c32cd\n'
In [42]: tn.read_very_eager()
Out[42]: b''
In [43]: tn.write(b'settings.attributes["BOT_NAME"]\n')
Telnet(127.0.0.1,6023): send b'settings.attributes["BOT_NAME"]\n'
In [44]: tn.read_until(b'\n>>>', timeout=10)
Out[44]: b''
In [45]: tn.read_all()
---------------------------------------------------------------------------
timeout Traceback (most recent call last)
<ipython-input-45-a95423c432d1> in <module>
----> 1 tn.read_all()
...[the traceback details is omitted]...
timeout: timed out
同时,在Scrapyd的日志中,我遇到了一些与telnet相关的未处理错误:
2019-03-14T22:01:28+0800 [Launcher,120868/stderr] Unhandled error in Deferred:
Traceback (most recent call last):
Failure: twisted.conch.telnet.OptionRefused: twisted.conch.telnet.OptionRefused:b'\x01'
2019-03-14T22:01:42+0800 [Launcher,120868/stderr] Unhandled error in Deferred:
Traceback (most recent call last):
Failure: twisted.conch.telnet.AlreadyDisabled: twisted.conch.telnet.AlreadyDisabled:b'\x01'