简体   繁体   中英

Python and telnetlib on 2.7. Totally not working for me

Below is the streaming data that i get when I connect from a command line. Yet..quit shocking...I get no data from from python. Why cant I print to screen the output? One would think I should just connect to to server, ready very eager.

tn = telnetlib.Telnet()
tn.open(HOST, TRADE_PORT)
while True:
 print '-',tn.read_very_eager()
- 
- 
- 
- 

Below us a working telnet session on same machine.

ubuntu@ubuntu:~$ telnet 222.222.222.222 2000
Trying 222.222.222.222...
Connected to 222.222.222.222.
Escape character is '^]'.
S=SXL,P=157.00,Q=3221,T=130621,N=40111759,E=371993|S=SXL,P=157.00,Q=45,T=130621,N=40111760,E=371994|S=SXL,P=157.00,Q=1401,T=130621,N=40111761,E=371995|S=SXL,P=157.00,Q=46,T=130621,N=40111762,E=371996|S=SXL,P=157.00,Q=37,T=130621,N=40111763,E=371997|S=SXL,P=157.00,Q=60,T=130621,N=40111764,E=371998|S=RIO,P=6514.50,Q=57,T=130621,N=10085304,E=371999|S=SXL,P=157.00,Q=39,T=130621,N=40111765,E=372000|S=SXL,P=157.00,Q=701,T=130621,N=40111766,E=372001|S=SXL,P=157.00,Q=119,T=130621,N=40111767,E=372002|S=SXL,P=157.00,Q=120,T=130621,N=40111768,E=372003|S=SXL,P=157.00,Q=47,T=130621,N=40111769,E=372004|S=SXL,P=157.00,Q=22,T=130621,N=40111770,E=372005,C=XT|S=SXL,P=157.00,Q=98,T=130621,N=40111771,E=372006|S=SXL,P=157.00,Q=924,T=130621,N=40111772,E=372007|S=SXL,P=157.00,Q=381,T=130621,N=40111773,E=372008|S=SXL,P=157.00,Q=221,T=130621,N=40111774,E=372009|S=SXL,P=157.00,Q=220,T=130621,N=40111775,E=372010|S=SXL,P=157.00,Q=313,T=130621,N=40111776,E=372011|S=RIO,P=6514.00,Q=61,T=130621,N=10085305,E=372012|S=RIO,P=6514.00,Q=32,T=130621,N=10085306,E=372013|S=PMV,P=762.00,Q=17,T=130621,N=40111777,E=372014|S=RIO,P=6514.00,Q=8,T=130621,N=10085307,E=372015|S=RIO,P=6514.00,Q=18,T=130621,N=10085308,E=372016|S=RIO,P=6514.00,Q=65,T=130621,N=10085309,E=372017|S=AMP,P=456.50,Q=129,T=130621,N=20091811,E=372018|S=AMP,P=456.50,Q=482,T=130621,N=20091812,E=372019|S=GPT,P=353.50,Q=109,T=130621,N=20091813,E=372020|S=RSG,P=47.50,Q=194,T=130621,N=10085310,E=372021|S=AGK,P=1499.00,Q=147,T=130621,N=40111778,E=372022|S=AGK,P=1499.00,Q=183,T=130621,N=40111779,E=372023|S=AGK,P=1499.00,Q=1,T=130621,N=40111780,E=372024|S=AGK,P=1499.00,Q=183,T=130621,N=40111781,E=372025|S=AGK,P=1499.00,Q=29,T=130621,N=40111782,E=372026|S=AGK,P=1499.00,Q=77,T=130621,N=40111783,E=372027|S=AGK,P=1499.00,Q=21,T=130621,N=40111784,E=372028|S=AGK,P=1499.00,Q=492,T=130621,N=40111785,E=372029|S=AGK,P=1498.50,Q=68,T=130621,N=40111786,E=372030|S=AGK,P=1499.00,Q=7,T=130621,N=40111787,E=372031|S=AGK,P=1499.00,Q=25,T=130621,N=40111788,E=372032|S=SYDDA,P=388.00,Q=50,T=130621,N=30083122,E=372033|S=PCL,P=6.10,Q=145,T=130621,N=30083123,E=372034|S=VAS,P=6727.00,Q=744,T=130622,N=30083124,E=372035|S=REA,P=4081.00,Q=2,T=130622,N=40111789,E=372036|S=MMS,P=1269.00,Q=2,T=130622,N=30083125,E=372037|S=DMP,P=1488.00,Q=2,T=130622,N=40111790,E=372038|S=WPL,P=3733.00,Q=24,T=130622,N=30083126,E=372039|S=NWS,P=1928.00,Q=1,T=130622,N=40111791,E=372040|S=WBC,P=3218.00,Q=118,T=130622,N=20091814,E=372041|S=WOR,P=1610.00,Q=9,T=130622,N=30083127,E=372042|S=NWS,P=1928.00,Q=3,T=130622,N=40111792,E=372043|S=SUN,P=1298.00,Q=50,T=130622,N=20091815,E=372044|S=WES,P=4264.00,Q=1,T=130622,N=30083128,E=372045|S=RIO,P=6515.00,Q=1,T=130622,N=10085311,E=372046|S=SUL,P=1360.00,Q=6,T=130622,N=40111793,E=372047|S=WES,P=4264.00,Q=43,T=130622,N=30083129,E=372048|S=QBE,P=1566.00,Q=46,T=130622,N=20091816,E=372049|S=RIO,P=6515.00,Q=16,T=130622,N=10085312,E=372050|S=WOW,P=3347.00,Q=48,T=130622,N=40111794,E=372051|S=ORI,P=2302.00,Q=13,T=130622,N

使用tn.read_some() (阻塞)而不是tn.read_very_eager() :它将在返回之前等待数据可用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM