Ubuntu server 12.0.4 SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

Ran into some trouble with Ubuntu 12.0.4 and an “SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure” error while accessing the Zoho Docs API through Python. Apparently Zoho’s API endpoint enforces a certain SSL version. The full python error was:

  1. SSLError: [Errno 1] _ssl.c:504: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

After ruling out python and openssl, the fix was to simply update to Ubuntu through apt:

  1. apt-get update
  2. apt-get upgrade

And for the hell of it did a distribution upgrade:

  1. apt-get dist-upgrade
Posted in Uncategorized | Tagged , , , , , , , , , | 1 Comment

django-simple-redis-admin: Manage redis within the django admin

It’s been a while since I talked about anything i’ve been coding. A few months ago I released Django Simple Redis Admin, which allows you to manage redis cache keys within the Django admin. Something that annoys me with other django admin packages is the requirement to add database tables for their packages. django-simple-redis-admin gets around this by making a django model on the fly. No need for tables, just plug and play. Hopefully in the future i’ll be adding some filters and speeding things up. Check out django-simple-redis-admin on my GitHub page.

Posted in Django | Tagged , , , , , , | Leave a comment

python-cloudcracker: a class to interface with the CloudCracker API

So I released a quick python class to interface with the CloudCracker API. CloudCracker is a new online password cracking service. Upload a pcap file, pay via BitCoin or Stripe, and they will crack the password for you. Pretty cool. Check out CloudCracker at cloudcracker.com and check out python-cloudcracker on GitHub.

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Ultramemcache: python-ultramemcached and django-ultramemached-cache

A few months ago I came across a package on GitHub called Ultramemcache, which was described as “Ultra fast memcache client written in highly optimized C++ with Python bindings.”

Using Ulramemcache, I modified the common python-memcached library to use Ultramemcache, making sure it could be used as a drop in replacement. Check out python-ultramemcached on my GitHub page.

I also put together a django cache backend using Ultramemcache. This currently does not require my python-ultramemcached library. Check out django-ultramemcached-cache on my GitHub page.

Posted in Django | Tagged , , , , , , , , | 2 Comments

A python class for the Exact Target XML api

After dealing with Exact Target‘s XML api for their email list management system, I decided to package up a few functions into a class. Check out python-exacttarget on my GitHub page.

Posted in Uncategorized | Tagged , , , , , , , | 2 Comments

Django runserver and gevent; NotImplementedError: gevent is only usable from a single thread

Hey. So I ran into a problem when using Django runserver and Requests for Python. Specifically, when running runserver, I came across the error:

  1. NotImplementedError: gevent is only usable from a single thread

To fix this, you need to run the gevent monkey patch in your projects manage.py.

Add the following lines in the __main__ of your manage.py

  1. from gevent import monkey
  2. monkey.patch_all()

Your main will look as follows:

  1. if __name__ == "__main__":
  2.     import gevent
  3.     from gevent import monkey
  4.     monkey.patch_all()
  5.     execute_manager(settings)
Posted in Uncategorized | Tagged , , , , , , , | 4 Comments

phpFlickr 3.1 cache unserialize error

I came across a problem today with phpFlickr 3.1 and the way it handles its database caching. I believe it has to do with commas in the serialized data that is being inserted into the cache table. After grabbing the cache result php gave me this error in the phpFlickr library:

  1. Notice: unserialize(): Error at offset phpFlickr.php

To fix this error you need to base64 encode and decode the data going into the database.

in phpFlickr modify line 144 to decode the response:

  1. return base64_decode($result['response']);

line 177 on cache row update:

  1. $sql = "UPDATE " . $this->cache_table . " SET response = '" . str_replace("'", "''", base64_encode($response)) . "', expiration = '" . strftime("%Y-%m-%d %H:%M:%S") . "' WHERE request = '" . $reqhash . "'";

line 180 on cache row insert:

  1. $sql = "INSERT INTO " . $this->cache_table . " (request, response, expiration) VALUES ('$reqhash', '" . str_replace("'", "''", base64_encode($response)) . "', '" . strftime("%Y-%m-%d %H:%M:%S") . "')";

Thanks to David Walsh for his php serialize tips:

Posted in php | Tagged , , , , , , , , , , , | 2 Comments

Django AuthenticationForm and non field errors

Here’s a quick tip for the built in Django AuthenticationForm in django.contrib.auth.forms: use the non_field_errors method when trying to display the incorrect user/pass error. The error is raised in the general clean method and is not bound to any field, so using form.errors doesn’t give you the error message itself.

  1. <div class="error">
  2.     {{ form.non_field_errors }}
  3. </div>
Posted in Django | Tagged , , , , , , , | Leave a comment

Django forms: Adding a blank option to a required choice field

Recently I came across a problem where I had a django form choicefield that needed to be required, but also needed a blank choice in case the user didn’t see the field and incorrectly submitted the first value. I saw a stack overflow post recommending to make a clean method to check that the first choice isn’t selected. That post is here:


… but a better way to do this is to simply leave the value of the blank choice as an empty string, which will invalidate the form without any extra clean method, like below:

  3.     ('', '——–'),
  4.     ('1', 'choice one'),
  5.     ('2', 'choice two'),
  6. )
  8. class ChoiceForm(forms.Form):
  9.      choice_field = forms.ChoiceField(choices=CHOICES_WITH_BLANK)
Posted in Django | Tagged , , , , , , | 1 Comment

Django forms: passing variables to a modelchoicefield

So I came across the problem of needing to filter my Django ModelChoiceField queryset by a variable in my view. Specifically I needed to pass the current selected state to the ModelChoiceField queryset. The best way I found to do this is to initialize the form with my state var in the initial:

  1. state = 'OH'
  2. form = LocationForm(initial={'state':state})

After that, instead of creating the field the traditional way, you can append the field to the self.fields dictionary within the init, enabling you to pass the initial state variable into the queryset of the field. Here is my form:

  1. class LocationForm(forms.Form):
  3.     def __init__(self, *args, **kwargs):
  4.         super(LocationForm, self).__init__(*args, **kwargs)
  5.         self.fields.insert(len(self.fields)-1'location',
  6.                            forms.ModelChoiceField(queryset=Location.objects.filter(state=self.initial['state'])))
  8.     first_name = forms.CharField(50, label="First Name")
  9.     last_name = forms.CharField(50, label="Last Name")
  10.     address = forms.CharField(60, label="Street Address")
  11.     city = forms.CharField(40, label="City")
  12.     state = USStateField()
  13.     zip = USZipCodeField()

Self.fields is a Django SortedDict, and it’s insert method takes the index to insert to, the key, and the value.

Posted in Django | Tagged , , , , , , , | Leave a comment