Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Using httplib to read a file online

Thread Tools

Using httplib to read a file online

Oyvind Ostlund
Posts: n/a
I am trying to read a file online, and was just testing a bit. This is what I tried.

import sys, httplib
showlines = 6

servername, filename = sys.argv[1:] # cmdline args?
servername, filename = '', '/index.php'

print servername, filename
server = httplib.HTTP(servername) # connect to httpsite/server
server.putrequest('GET', filename) # send request andheaders
server.putheader('Accept', 'text/html') # POST requests workhere too
server.endheaders() # as do cgi script
file names

errcode, errmsh, replyheader = server.getreply() # read reply info headers
if errcode != 200: # 200 means success
print 'Error sending request', errcode
print 'Message', errmsh
print 'RepHeader', replyheader
file = server.getfile() # file obj for data
data = file.readlines()
file.close() # show lines with eolnat end
for line in data[:showlines]: print line, # to save, write datato file

There is a server called and a file called index.php on it, but why doesn't it work. If I changed it to '' and 'index.php' then it worked. What is the difference? Anyone have a qlue?''

Thanks in advance
- ии -
Reply With Quote
Posts: n/a
Why are you using httplib rather than urllib2 ?

Best Regards,


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
httplib hangs in read / strace says recvfrom() Michael Bacarella Python 0 09-13-2007 11:57 PM
File upload using httplib alastair Python 3 07-26-2004 11:45 PM
Non-blocking read() in httplib? Marcin Ciura Python 4 07-13-2004 05:50 PM