Friday, April 17, 2009

Client certificates with urllib2

First let's get pem formatted file with certificate and key from your *.pkcs12 or *.pfx file with openssl.
openssl pkcs12 -in file.p12 -out file.pem -nodes


Now we need to extend standart HTTPSHandler( I found it here. I added timeout to getConnection method. ) and sent instance of it to urllib2's build_opener.
import urllib2, httplib
class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
def __init__(self, key, cert):
urllib2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert
def https_open(self, req):
#Rather than pass in a reference to a connection class, we pass in
# a reference to a function which, for all intents and purposes,
# will behave as a constructor
return self.do_open(self.getConnection, req)
def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert)

opener = urllib2.build_opener(HTTPSClientAuthHandler('/path/to/file.pem', '/path/to/file.pem.') )
response = opener.open("https://example.org")

print response.read()

Thursday, April 16, 2009

Harmonica

Harmonica was one of things I want to have. It's small and sounds cool. I associate it with Wild West and cowboys.

A month ago I saw a harmonica in music store and I said myself to buy it.

Today I purchased another one than I saw. I didn't know types, how to play on it. The thing I assess was count of  holes )). I choose Yamaha SS 220.

I found that it needs to inhale too, not only blow )). It takes half an hour to understatnd positions of note and I played simple melodies.

Found some information on web about harmonicas. Type of mine is Chromatic Single. It has two rows of holes. Upper row gives C# scale and lower gives C scale. There are 44 holes, 22 on each row.

P.S. There, in Yamaha music store, I played on electronic drums. They're sooo coool. I wish them. Drums are compact it's important for my appartment. You control a volume and also they're pluggable to headphones. Aaaaaaa!!! I want I want  I want them. With my real drums I feel discomfort when I play cause of my neighbors and thin walls. Somebody, give me 1500 dollars!

Powered by Blogger.