469,962 Members | 2,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,962 developers. It's quick & easy.

Using httplib to read a file online

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 = 'noteme.com', '/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 noteme.com and a file called index.php on it, but why doesn't it work. If I changed it to 'vbforums.com' and 'index.php' then it worked. What is the difference? Anyone have a qlue?''

Thanks in advance
- -
Jul 19 '05 #1
1 2006
Why are you using httplib rather than urllib2 ?

Best Regards,


Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Karl Witmann | last post: by
3 posts views Thread by alastair | last post: by
1 post views Thread by Brian Beck | last post: by
reply views Thread by Laszlo Zsolt Nagy | last post: by
reply views Thread by Pieter Edelman | last post: by
reply views Thread by Robert | last post: by
4 posts views Thread by JuHui | last post: by
5 posts views Thread by runningwild | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.