Development

MySQL-python EnvironmentError: mysql_config not found

I’ve been trying to get the Tornado Web Server setup on my Mac OS 10.6 Snow Leopard laptop. There are tons of dependencies it has been a pain in the ass.

Install MySQLdb python driver.

Download latest MySQL_python.

tar xzf MySQL-python-1.2.3c1.tar.gz
cd MySQL-python-1.2.3c1
python setup.py build

Build process may give you an error

EnvironmentError: mysql_config not found

This happens because your mysql installation may be non-standard. Mac OS installations are typically wacky. If you get this error figure out where your mysql_config binary resides.

I found my bin file at /usr/local/mysql/bin/mysql_config

cd MySQL-python-1.2.3c1
vim  site.cfg

In the MySQL-python site.cfg file search for these lines…

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config

Replace mysql_config with your path. My executable was in a different place from where the build script thought the executable would be and the mysql_config executable was not in my resource PATH. I have a Mac 10.6 machine and I probably installed MySQL 5 using MacPorts.

Now you should be able to successfully build and install the MySQL for Python library.

python setup.py build
python setup.py install

Authenticate REST requests to the Amazon Product Advertising API using Python

SowaCS Consulting’s Amazon Web Service Query Signer. Download the file called awsquerysigner_py.zip

As of August 15, 2009 Amazon required all API queries to have a special authentication signature. SowaCS Consulting has published a simple Python class (Python library?) that does the dirty work to sign your REST calls to the Amazon Product Advertising API. The code is on the website but they also offer a query signing service.

Back Story:

I finally got the gumption to attempt to tie in some AWS (Amazon Web Services) things into some of the websites I’m running because I want the affiliate advertising to blend in with my pages in a cleaner fashion. Unfortunately Amazon made it a lot harder for chumps like me to make API calls because of their newly enforced requirements that all requests be signed with a special hash signature. Steps involved to sign an Amazon REST request

  • Take query params, re-order them by byte-value and make them UTF-8.
  • url encode each key-value query parameter
  • replace any “+” and “~” characters in the strings with url encodings
  • add a timestamp
  • Build a text string to prepare for hashing
  • Encode signature using HMAC and SHA256
  • Send request, and receive REST response.

This process sounds easy, but I couldn’t figure it out. I wrestled with Amazon’s Product Advertising API Documentation but the examples mostly uninformative. Thankfully, I came across a helpful post in the developer forums that points to SowaCS consulting. Naturally when looking at the code theirs is much cleaner, more flexible and it actually works. It’s not superb code but it IS way better than anything I would ever write. I really ought to go back to school…

Clean html for content pasted from Word into YUI rich text editor

I’ve been trying to come up with a good way to strip out crappy HTML pasted from MS Word into the Yahoo UI’s rich text editor. Thankfully I am not the only person with this problem and my procrastination pays off! Somebody else created a script to do it for me.

AntsCode has a nice tool to Strip Formatting on Paste using YUI Rich Text Editor

His solution is so simple I feel stupid for not thinking of it. He attaches a listener for the cut and paste command. When you paste into the Rich Text Editor it uses the standard YUI HTML stripper, then he goes in and strips out the unwanted word HTML formatting using a series of regular expressions. Clever.

Syndicate content