The blagotube home of Sune Kirkeby. Here are rambling rants and some bits of code.

24. Mar
2013

SNI-support for requests

The ssl module in Python 2’s standard library does not support the SNI TLS-extension, and it probably never will, which means that the brilliant requests HTTP library is also missing SNI-support on Python 2.

Now that urllib3 has a contrib-module for SNI-support on Python 2 this might change, but if you don’t want to wait for the updated urllib3 to be included in a requests release, you can monkey-patch requests yourself:

  1. Install the required packages:

    pip install pyOpenSSL ndg-httpsclient pyasn1
    
  2. Download requests_pyopenssl.py and put it somewhere on your PYTHONPATH.

  3. Monkey-patch requests somewhere early in your application (possibly in a sitecustomize module):

    try:
        import requests_pyopenssl
        from requests.packages.urllib3 import connectionpool
        connectionpool.ssl_wrap_socket = requests_pyopenssl.ssl_wrap_socket
    except ImportError:
        pass
    

If you want to test that it works, the following Python script should print “requests SNI-support Ok” when run:

try:
    import requests_pyopenssl
    from requests.packages.urllib3 import connectionpool
    connectionpool.ssl_wrap_socket = requests_pyopenssl.ssl_wrap_socket
except ImportError:
    raise

import requests
for host in ['alice', 'bob', 'carol', 'dave', 'mallory', 'www']:
    response = requests.get('https://%s.sni.velox.ch' % host)
    html = response.content.decode('utf-8', 'replace')
    assert 'Great!' in html, host

print 'requests SNI-support Ok'
This post was written by Sune Kirkeby on 2013-03-24, and claimed to be mostly about code. Also, it has these tags: python requests http ssl sni.
23. Mar
2013

Pelican

No more crufty, home-grown static-site-generation — this is now generated by shiny pelican.

This post was written by Sune Kirkeby on 2013-03-23, and claimed to be mostly about meta.
23. Mar
2013

Ubuntu vs sitecustomize.py

Sometimes it is almost like the Ubuntu developers go out of their way to annoy the rest of the world, this time (for ancient values of “this time”) the Python package-maintainer decided to add a sitecustomize module to the Python standard library. This is not what sitecustomize is for, sitecustomize is for “performing arbitrary site-specific customizations”.

This is pretty annoying, when you want to use sitecustomize for its intended purpose, so puppet to the rescue:

file { ['/usr/lib/python2.7/sitecustomize.py',
        '/usr/lib/python2.7/sitecustomize.pyc',
        '/usr/lib/python2.7/sitecustomize.pyo']:
    ensure => removed,
}
This post was written by Sune Kirkeby on 2013-03-23, and claimed to be mostly about code. Also, it has these tags: ubuntu python puppet.
13. Mar
2006

New bestest Firefox extension

I have a new favourite Firefox extension: click2tab.

I can’t count how many times I have pressed ctrl+w in a Firefox textarea, trying to rub out the last word I wrote, and instead been faced with loosing my entire browser. “Grrrr,” is my usual response to this.

In my opinion Firefox should recognize that ctrl+w in a textarea very probably is a Unix person making a bad mistake. Alas, it does not. click2tab does not save me from making the mistake, but it lets me undo the close tab operation. Which is just as swell.

Yay!

This post was written by Sune Kirkeby on 2006-03-13, and claimed to be mostly about rambling.
26. Feb
2006

The Classics

For the past 10 years the only fiction I have read is sci.fi., with a few detours into fantasy. It started some time during late primary school, when the slow, painful death of my literature classes took their toll. Those classes were meant to introduce us to classic literature and good writing in general. I thought all of the books we read were mind-numbingly dull. So depressingly, horribly dull that in spite I didn’t read a single book for literature class all through high school.

The sad thing is, then and now, I love reading. So, the danish primary education system turned a confessed bibliophile off classic literature. Which has bugged me ever since: I always felt there must be a good reason classic literature is considered.. well, classic. So, once in a while, when shopping science fiction, I would also buy a classic, thinking: “Maybe, this one is worth reading.” Alas, those books always went to the bottom of the pile. And stayed there.

But. Recently I dug into the book pile next to my reading chair, and decided to give one of the classics a try. Orwell’s Animal Farm came first. I was right, Animal Farm is a very good book. Next I picked up Kafka’s The Trial. The cover says “the masterpiece of the 20th century”; that must mean the book is a classic. And, so far the story captivates me (pun somewhat intended.)

A whole new world of books. Yay! :)

This post was written by Sune Kirkeby on 2006-02-26, and claimed to be mostly about rambling.
25. Feb
2006

E-mail-disclaimer-virus parody

Noticed this gem in Carlo C8E Miron’s signature:

Disclaimer: If I receive a message from you, you are agreeing that: 1. I am by definition, “the intended recipient”. 2. All information in the email is mine to do with as I see fit and make such financial profit, political mileage, or good joke as it lends itself to. In particular, I may quote it on USENET or the WWW. 3. I may take the contents as representing the views of your company. 4. This overrides any disclaimer or statement of confidentiality that may be included on your message.

That very nicely sums up how I feel about the e-mail-disclaimer virus, which seem to have infected a large number of work-computers.

This post was written by Sune Kirkeby on 2006-02-25, and claimed to be mostly about rambling.