using telnetlib in python/cgi to config a router and display to webpage

using telnetlib in python to configure a router. i'm using cgi to display the python script to a browser.
i'm having trouble troubleshooting the code because cgi just display's an error screen 'internal server error'
so, i really don't see where i'm making the mistake. i can run the python script through the python interpreter, but that's just a hassle.

any suggestions on how to troubleshoot the output? i've tried using
print "Content-type:text/plain\n" as opposed to "Content-type:text/html\n" so as to just display the unformatted output without html formatting, but i still am not seeing where i'm making mistakes.

i know i can cat /var/log/httpd/error_log

but i guess what i'm asking is if anyone can give me some more specifics about what is actually going on.
i understand this:
telnetlib is a module that'll open a socket to the router or switch.  the physical and data link connection we're not going to see, the network layer is addressed by the ip which i have set to a variable and is here
host = ""
tn = telnetlib.Telnet(HOST, timeout=TIMEOUT)
any further specifics of communication is held within the actual module telnetlib -- socket or transport layer tcp settings.

the server 'sends' the message, encapsulated at what? layer 7 down through layer 2 as the data communications model/osi specifies.. it goes over the wire and over to the client which decapsulates the packet and sends it back up to the telnet application.

i understand i can't see the output of the client(the switch or router) because stdout is defined on the router and it's not the socket that the command came in on, so it has no transport back to the server.  it is buffered? in the object?

this is where i'm getting lost

i know i'll eventually use output = tn.read_all() to display the output on the website, but that, at least in part, is failing



i can provide more code. i think these are all fairly standard things to non-newbies like me
DavidCyberNetSec GuyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Unsure exactly what you're asking.

Telnet != HTTP, so you can use telnetlib... very easily... to conduct an HTTP conversation.

To accomplish this, try this sequence...

1) Use curl to connect to your router.

2) You will not be able to see any /var/log/httpd/error_log entries of use, unless these logs are available on your router (where the HTTP server is running).

3) Once you get #1 working, then if you must, you can always convert your #1 command line curl to use libcurl in some language like Python.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidCyberNetSec GuyAuthor Commented:
Telnetlib is a python module
DavidCyberNetSec GuyAuthor Commented:
i'm not sure i understand the answer, but i'll keep it in the repository for future reference. i was trying to do something specifically with telnetlib for a class, but will look into the other things .. i've heard of curl and would like to see what it can do ... isn't it just a downloader of sorts?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.