Warning: mysqli_query(): (HY000/1712): Index wp_posts is corrupted in /home/thermopyle/blog.contriving.net/wp-includes/wp-db.php on line 1876
python | Contriving

Tag Archives: python

MySQL and Python 2.6 on Windows, Redux

As I noted before, getting a version of MySQLdb that works for Python 2.6 on Windows is an exercise in frustration.  Until now.

An anonymous commenter on the previous post pointed to a web page with instructions for compiling MySQLdb with Visual Studio.  This was quite the salvation to me as I have no experience with Visual Studio or really any sort of compiling on Windows at all.

The only thing lacking in those instructions is the bit about “vsvars32.bat”.  It says:

make sure “vsvars32.bat” exists in “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools”

That’s the last mention of that file.  The problem is that you have to actually run that batch file prior to compiling.

The only other adjustments I had to make were to account for the fact that I’m using Visual Studio 2008 which has a different path than Visual Studio 2005.

All that resulted in my own Windows installer for MySQLdb for Python 2.6.  This was compiled on Windows 7 64-bit, I’m not sure how it’ll work on other operating systems, but if it doesn’t work for you make a comment and I’ll see if I can compile a version for your environment.

Download it here.

JSON feed for Source servers

I’m kind of a statistics whore.

To further my pursuit of more statistics, I’ve developed a Python CGI which provides a JSON feed of all sorts of information about servers based on Valve’s Source engine.

This script has three dependencies outside of what is in the standard Python library:

Once you have those installed (worst-case scenario just drop them in the same directory as sourcejson.py), you need to edit sourcejson.ini.  This file just has three options: rcon_pass, ip, and port.  If you don’t have the rcon password for the server you wish to monitor just leave it blank.

To access the JSON feed just use the url to sourcejson.py.  Something like this:

http://YOUR_DOMAIN/sourcejson.py

To access the extended information that having an rcon password allows use:

http://YOUR_DOMAIN/sourcejson.py?info=extended

If you use the extended format, but haven’t provided an rcon password in sourcejson.ini, it will just default to the basic feed.

Included in the zip is a .htaccess to prevent directory listings, which will help protect the contents of sourcejson.ini.

Download sourcejson here!

Using Python 2.6 + MySQL on Windows is nearly impossible

Update:  I made progress on this issue.  See my newer post here.

If you’re interested in writing Python scripts on Windows which access MySQL databases, be sure you avoid Python 2.6.

The standard way to interact with a MySQL database via Python is to install the mysql-python package The problems arise because of several things.

  1. mysql-python still doesn’t have compiled binaries for 2.6
  2. Windows doesn’t ship with a C compiler.
  3. It’s a SOB to use any of the free C compilers to compile from source.

A couple of kind souls have provided their own compiled versions in this forum thread, but neither of the provided versions works on the two Windows machines I’ve tried them on.

I tried following the official directions to compile on windows using the “setup.py build”-method, but MinGW spits out several bajillion lines indicating the following(bolded part indicates error found over and over again):

C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\opt/mysqlclient.lib(./mysqlcli
ent.dir/relwithdebinfo/inftrees.obj):(.text[_inflate_table]+0x4e3): undefined re
ference to `@__security_check_cookie@4′
collect2: ld returned 1 exit status
error: command ‘gcc’ failed with exit status 1

There’s very little useful information to be found from a google search on this, so as it stands, I’m pretty much unable to use Python 2.6 + MySQL.

I really wonder why MySQL support isn’t packaged with Python.  It’s not like accessing MySQL is an unheard of operation…

How I recovered my photos and much of the metadata with a few tools (Part 2)

This is a continuation of another post detailing how I recovered thousands of photos from an accidentally formatted hard drive. Read that post here.

The Problem – Part 2

At this point, I was definitely breathing easier, but there was still a lot of problems to deal with.  The problem with what PhotoRec does is that, it doesn’t look at the data on your hard disk at the file/directory level.  It looks at the raw data on the hard drive and recognizes if it’s a picture and then restores it to the location of your choice.  This means that filenames and directory structure are lost.  This also means, that nearly every jpeg file on the formatted hard drive was recoved…including tens of thousands of images from Firefox’s cache along with hundreds(thousands?) of other various images like wallpapers that I’ve downloaded over the years, with no obvious way to distinguish between them and actual photos.
Read more »