Python’s smtplib false authentication failures

June 19th, 2008

I ran into a case where Python’s smtplib could not authenticate against some SMTP servers, while others worked just fine (with good valid logins). After some research into the SMTP protocol, a few debug sessions and a pinch of telnet connections to the SMTP server it became apparent that some servers just have quirks which cause authentication to fail when its handled by smtplib.
It seems that smtplib’s login() method will choose its own authentication method, and if it can will use a MD5 Hash, which failed on some servers for some unknown reason.

The solution:

Catch the failure and send manual “AUTH LOGIN” commands with a base64 encoded username and password:

import base64
try:
    # attmept a 'standard' login
    smtp.login( username , password )
except SMTPAuthenticationError, e:
    # if login fails, try again using a manual plain login method
    smtp.docmd("AUTH LOGIN", base64.b64encode( username ))
    smtp.docmd(base64.b64encode( password ), "")

Built in wifi in Ubuntu Hardy on Thinkpad T61p

May 28th, 2008

Just  a short note to any googling bodies who like me might be stuck on this problem for days as I have been…

I could not get the built in IBM wifi card (Atheros, recognized as “AR5212 802.11abg NIC” in lshw -C network) on my  Thinkpad  T61p to work in Ubuntu 8.04 (Hardy) as well as other versions of Ubuntu on Live CD.  A PCMCIA card of the same chipset worked great and the internal card worked fine in XP, but not in linux. No matter what I did (and I did a LOT).
The solution was, as always, a simple one. I took the latest madwifi source from their subversion repository, and compiled it. Then took the latest wpa_supplicant and complied that against the madwifi source. That did the trick!

Update:

Run this to turn on the wifi blinkenlight (taken from here):

sysctl -w dev.wifi0.ledpin=1
sysctl -w dev.wifi0.softled=1

				

No Escape!

May 19th, 2008

This is a photo of a door leading to the lifts in the maternity ward of Kingston Hospital. I’m not sure its the right thing to show women who are about to experience child birth…
It didnt bother Shiloh, my second son to pop out that night though. ;o)

No Escape

Return of the Insert - Id values from ColdFusion Insert queries for MySql

April 29th, 2008

In postgreSQL you can create insert statements that return the new id by simply appending “returning id_field” after the insert statement (where id_field is the name of your automatic id field). You don’t get that luxury with mySql (why?).
To achieve the same result you’d have to perform two queries inside a transaction: the insert itself and a “select last_insert_id()” query.

However I just found out this little trick: mySql’s connector by default does not allow multiple queries to be executed (using the ; terminator). But if you add this parameter to the JDBC url you will be able to execute multiple queries inside one cfquery tag:

allowMultiQueries=true

You can now perform insert queries that return the new id:

<cfquery name=”insert” datasource=”dsn”>
insert into temp (val) values (’test’);
select last_insert_id() as new_id;
</cfquery>

This query will have a result set containing a new_id field with the newly inserted id in temp.

You will have to take extra care thought. This option is false by default to reduce the chance of sql injection attack. Make sure you use the cfqueryparam tag and not just embed #vars# in your sql.

See here for a full list of mySql’s Connector J settings.

ColdFusion Performance - The CF8 Summary

April 18th, 2008

I’ve retested all of my previous ColdFusion performance tests on ColdFusion 8 to see where things stand today.
To get straight to the point:

Strict Vs. ‘Chilled’ typing - Not only its still better to avoid strict typing if performance matters, Adobe have included a CF Admin setting allowing to disable strict typing in production servers. This makes it possible to use strict typing for development, and once in live production environment, disable all type checks. Great.

Inheritance Tax - Still stands. Seems like every object in the inheritance chain will add a performance tax even if its not doing anything. Shame.

Prepared Statements - Not related to a specific ColdFusion version, so still stands (I must admit I skipped retesting this one)

CFSWITCH Vs CFIF - Whoo hoo!!! This is actually no longer a valid case. Now it seems as if the opposite is true, and cfswitch is faster then cfif/else. Happy Times!

String Concatenation - Arrays are still the fastest, but you can also use the java concat() method to reach the same effect with better code readablilty (some_string.concat(”another string))

Kadoink now in Public Beta!

October 13th, 2007

Kadoink is now officially in public beta and is open for all.

One of the first widgets (flex based) can be seen and experienced in the Hollywood Undead MySpace page.

Take it for a spin. I’d love to hear any feedback you might have.

http://www.kadoink.com

Harel

Message to Dog

September 25th, 2007

Jason gave me this one. Its from somewhere near Gunnersbury station.
I don’t have a dog, but if you do and it can translate what’s written there, let me know please.

Message to Dog

The Conscientious Spammer

August 20th, 2007

As anyone who has a website which accepts public comments  knows, you do get unbelievable amount of spam comments. I personally find this extremely annoying, rude and unacceptable behavior for human beings or bots of any kind. That’s why I am force to moderate all comments before they are made public.

I got this very conscientious comment by galinagirll a few days ago :

“hello , you have a very nice site, but Im hired to leave advertising comments on sites, sorry i hate to do it but i have to . If you dont like advertising comments please send me an email with your site address to
tedirectory(at)yahoo(dot)com and I will not write on your site. Sorry for inconvenience.”

The link provided was for love dot com, which funny enough led to Aol dating…

I found it hilarious that the spammer also found it necessary to obfuscate her email address. I’m almost tempted to allow this comment through… almost…

Kadoink is a go!

August 17th, 2007

Its been in the making for a long time now, but its finally out (in obligatory beta mode): the Kadoink project is live at

http://www.kadoink.com

Kadoink is first a super messaging platform that can perform voice calls and SMS and be accessed from either a web front end, your mobile phone or an Instant Messenger client.
Its also a way to connect to your online communities while off line using just your mobile phone.
And its also a brilliant way to perform unlimited conference calls, REAL SMS chats of unlimited size (where each reply is received by all the chat participants), send audio files to people’s phones, record reminders to yourself or to other people, schedule calls and SMS, have flash based widgets to put on your own sites and supercharge them with all the Kadoink functionality and much much much more…
In short, its what twitter could have been had it had some more imaginative flair.

Some links to the first write ups about Kadoink below:

Mashable.com: http://mashable.com/2007/08/16/kadoink/

KillerStartups: http://www.killerstartups.com/Web20/kadoink–Moblizing-your-Socializing/

This post is tagged under ColdFusion, Java and Python because it utilizes all for its magic (there, that was the required shop-talk blurb)

Python, MySQL and UTF8… A slightly unholy trinity

July 25th, 2007

I spent a good two days trying to resolve a problem with a python based messaging application I’ve been working on.
The app was running as a daemon process, monitoring a database queue and sending any items on it.
The database, table and data are all UTF8 encoded. All was fine until an email that actually utilized the benefits of UTF and contained other characters than the usual English ones - the email that was sent came up as either garbage or a series of question marks. Same queue processed by ColdFusion worked fine. From python - no luck. WTF I said (well, I didn’t actually speak out the acronym, but I did utter the expanded version a few times, making sure I repeat the F word for good measure).

My first route was to tackle the email encoding issues but after a day of sweating it and getting no results, It dawned on me that perhaps I’m bashing my head on the wrong wall. A quick interactive shell session confirmed that - the data coming out from the queries was returning as garbage whenever an extended character was supposed to show. Absolutely nothing would make it display properly. The only half-assed thing that worked is encoding the utf8 data as latin1 (and later in the email mime part to set the encoding to utf8. That just didn’t feel right. Any character that could not be represented in latin-1 would have been either ignore, replaced or thrown a Unicode error.

Many Googles later, a long session at #python on undernet (thanks tommi) and a pinch of perseverance, I had a working solution. The secret ingredient is to add a charset=”utf8″ to your connection parameters, and use_unicode=True. The former will tell mySql that it should work in the utf8 character set. The latter is to tell python its on utf8.

I do recommend using DBUtils for connection pooling. It works a treat. My example below uses that to access the MySQLdb connection but I added an example for a more direct approach as well.

The conclusion - use Postgres... It is really really so much better, that once you give it a go, there’s no turning back.

import MySQLdb
from DBUtils.PooledDB import PooledDB
pool = PooledDB( creator = MySQLdb, mincached = 5, db = DB_NAME, host = DB_HOST, user = DB_USER, passwd= DB_PASS,
charset = “utf8″, use_unicode = True)
__db = pool.connection(0)
__cur = __db.cursor()
__cur.execute(”SELECT utf8_field FROM utf8_table WHERE this=that”)
row = __cur.fetchone()
print row[0]

Or if you don’t really fancy a connection pool:

import MySQLdb
__db = MySQLdb.connect(host=DB_HOST ,user=DB_USER ,passwd=DB_PASS,db=DB_NAME, charset = “utf8″, use_unicode = True)
__cur = __db.cursor()
__cur.execute(”SELECT utf8_field FROM utf8_table WHERE this=that”)
row = __cur.fetchone()
print row[0]

Bad Behavior has blocked 175 access attempts in the last 7 days.


Ordinary business man has nothing to do with the technique. A search engine optimization service useless if it is claimed to be "hi tech" but can't bring the results. People are looking for a smart but cheap web host. What required is a web design that can promote the business. The demand for personal web hosting service is rising quickly. Only a well planned pay per click campaign can bring the required results. The conclusion is that we need a technology that can fulfil the demands of cheap hosting. The shared web hosting must be simple regardless of the technique. Likewise, pay per click policy should bring some business instead of exhibiting our experties.