March 14th, 2001


more fun with Python

I started fiddling around with some python in the general direction of an LJ client while trying to stay off the phone the last hour.

I was waiting for a phone interview call which has not yet come. The nice, helpful Catbert (fourth) managed to determine that the fellow had got caught up in a meeting, which he admitted happens from time to time...I am to catch up with them tomorrow morning.

I had looked at the dev pages to see what I would need, (and they say it better ) so I knew I really just needed some simple web client code (HTTP GET, PUT) at the base of it. From wandering around in the Python Library Reference before, I knew it was really easy to get into any common internet protocols (Awhile back I hacked up a 7 line email client to see if I could..) so I started poking around their url and http libraries (urllib and httplib, respectively :) This is what I came up with in less than an hour:

 def fetch0(bone, meat):
	"""v0 Fetches file string meat from host bone by http"""
	import httplib
	h1 = httplib.HTTP(host=bone)
	h1.putrequest('GET', meat)
	h1.putheader('ACCEPT', 'text/html')
	h1.putheader('ACCEPT', 'text/plain')
	errcode, errmsg, headers = h1.getreply()
	if errcode == 200:
		f = h1.getfile()
		data =
		print data
		print errcode, errmsg

Drop this into a python interpreter or type it in, feed in a string pair, like so:


and it will merrily dump the HTML of the file to screen, or report the error code.

So simple it hurts.

  • Current Music
    Tori Amos - Blood Roses

IM Humour

 I don't ope snail when I know what it says, do you?
[Error: Irreparable invalid markup ('<sophestry (aim)>') in entry. Owner must fix manually. Raw contents below.]

<adric> I don't ope snail when I know what it says, do you?
<sophestry (aim)> Yes. I typically want to find out what it says.
* adric blinks.
* adric repeats: I don't open snail ..
<sophestry (aim)> That's why I open it..
<adric> huh?
<sophestry (aim)> To find out what it says.
* adric repeats: I don't open snail when I know what it says, why do you?
<sophestry (aim)> To find out what it says?
<adric> Okay, that's it. I'm posting this exchange.
<adric> gone.
<sophestry (aim)> Why don't you open snail?
* adric tries again:
<adric> When I know the content of a message in an envelope there is no
need to open the envelope (whose contents are already known to me)
<sophestry (aim)> Why do you not open snail when you don't know what it
<sophestry (aim)> oh.
<sophestry (aim)> All of this exchange was based on my misreading that
first post.
<adric> Uh-huh.
  • Current Music
    Tori Amos - Doughnut Song