Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4238320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:53:22+00:00 2026-05-21T02:53:22+00:00

I have an application that calls telnetlib.read_until(). For the most part, it works fine.

  • 0

I have an application that calls telnetlib.read_until(). For the most part, it works fine.
However when my app’s telnet connection fails, it’s hard to debug the exact cause. Is it my script or is the server connection dodgy? (This is a development lab, so there are a lot of dodgy servers).

What I would like to do is to be able to easily snoop the data placed into the cooked queue before my app calls telnetlib.read_until() (thereby hopefully avoiding impacting my app’s operation.)

Poking around in telnetlib.py, I found that ‘buf[0]’ is just the data I want: the newly-added data without the repetition caused by snooping ‘cookedq’.
I can insert a line right before the end of telnetlib.process_rawq() to print out the processed data as it is received from the server.

telnetlib.process_rawq ...
    ...  
    self.cookedq = self.cookedq + buf[0]
    print("Dbg: Cooked Queue contents = %r" % buf[0]  <= my added debug line
    self.sbdataq = self.sbdataq + buf[1]

This works well. I can see the data almost exactly as received by my app without impacting its operation at all.

Here’s the question: Is there a snazzier way to accomplish this? This approach is basic and works, but I’ll have to remember to re-make this change every time I upgrade Python’s libraries.

My attempts to simply extend telnet.process_rawq() were unsuccessful, as buf is internal to telnet.process_rawq()

Is there a (more pythonic) way to snoop this telnetlib.process_rawq()-internal value without modifying telnetlib.py?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:53:23+00:00Added an answer on May 21, 2026 at 2:53 am

    The easy hack is to monkey patch the library. Copy and paste the function you want to change into your source (unfortunately, process_rawq is a rather large function), and modify it as you need. You can then replace the method in the class with your own.

    import telnetlib
    
    def process_rawq(self):
        #existing stuff
        self.cookedq = self.cookedq + buf[0]
        print("Dbg: Cooked Queue contents = %r" % buf[0]
        self.sbdataq = self.sbdataq + buf[1]
    
    telnetlib.Telnet.process_rawq = process_rawq
    

    You could alternatively try the debugging built-in to the telnetlib module with set_debuglevel(1), which prints a lot of info to stdout.

    In this situation, I would tend to just grab wireshark/tshark/tcpdump and directly inspect the network session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that calls a number stored by the user. Everything works
I have an application that calls out to a web service. It runs fine
I have a Flex application that calls a function which searches a large document
I have a C# application that calls a stored procedure that produces an xml
I have created a console application that calls a method on a webservice. I
I have an ASP.NET application that calls other web services through SSL (outside the
I have a script that calls an application that requires user input, e.g. run
I have recently been working on a C# application that calls a webservice over
I have a .NET application that uses some API calls, for example GetPrivateProfileString .
We have built a web application that accepts SOAP messages, does some processing, calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.