Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Using httplib to read a file online (http://www.velocityreviews.com/forums/t346096-using-httplib-to-read-a-file-online.html)

Oyvind Ostlund 06-14-2005 03:35 PM

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

try:
servername, filename = sys.argv[1:] # cmdline args?
except:
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
else:
file = server.getfile() # file obj for data
received
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
- ии -

Fuzzyman 06-17-2005 11:25 AM

Re: Using httplib to read a file online
 
Why are you using httplib rather than urllib2 ?

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python



All times are GMT. The time now is 04:55 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.