Python ‘pip’ and Windows registry corruption

Background

In my recent post about setting up a 64 bit Windows Django development environment, I described an initial problem with Virtualenv which then led me through a whole series of problems and fixes and finally to what I thought was a working 64 bit Python development environment. However, I recently realised that the original underlying issue still remained, such that any attempt to install a new package using pip would result in failure due to that same error message.

For example, when I tried to install Beautiful Soup via pip, I got the following error:

C:\> pip install beautifulsoup4
Downloading/unpacking beautifulsoup4
Cleaning up...
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run

requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl
e=self.bundle)
File "C:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "C:\Python27\lib\site-packages\pip\req.py", line 292, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.s
etup_py, self.name))
File "C:\Python27\lib\site-packages\pip\req.py", line 265, in setup_py
import setuptools
File "C:\Python27\lib\site-packages\setuptools\__init__.py", line 12, in
from setuptools.extension import Extension
File "C:\Python27\lib\site-packages\setuptools\extension.py", line 7, in
from setuptools.dist import _get_unpatched
File "C:\Python27\lib\site-packages\setuptools\dist.py", line 15, in
from setuptools.compat import numeric_types, basestring
File "C:\Python27\lib\site-packages\setuptools\compat.py", line 19, in
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand
ler
mimetypes.init() # try to read system mime.types
File "C:\Python27\lib\mimetypes.py", line 361, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 263, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: must be string without null bytes or None, not str

Continue reading Python ‘pip’ and Windows registry corruption

Create a Django development environment on 64-bit Windows for Heroku deployment

Getting Started with Django on Heroku

This weekend I tried to follow Heroku’s Getting Started with Django article. Unfortunately for me, this article is clearly aimed at developers working in a “unix-style environment”, and I develop with a 64-bit Windows machine both at work and at home. Given that we are working with a Python-based framework, I foolishly assumed that it would be trivial to translate these instructions to Windows. How wrong I was.

This article summarises all the issues I encountered and how I eventually worked around them. I found most of the individual answers I needed via Google, but I couldn’t find a single resource that explains this whole process. I hope it saves you some time. The specific error-messages and console output were generated with 64-bit Windows 8.1, but I expect things to be basically the same with 64-bit Windows 7.

Continue reading Create a Django development environment on 64-bit Windows for Heroku deployment

How to embed third-party widgets such as Mixcloud into WordPress

There are now a huge number of third-party content providers that offer the ability to embed their content into your own website. YouTube is no longer the only media streaming service that you might want to include in one of your pages. Many other competing media streaming providers are now offering an API that should make it easy to embed their content. However, the question is what is the best way to include their content in one of your WordPress pages?

This post describes three different approaches to embedding third-party content. It is written for owners of self-hosted WordPress sites, but some of the techniques may also be applicable to sites hosted on WordPress.com. I will use the Mixcloud audio streaming service for the examples, specifically because it is not one of the out-of-the-box supported services in WordPress.

Continue reading How to embed third-party widgets such as Mixcloud into WordPress

TRAKTOR PRO Logo

Using the Numark Mixtrack Quad with TRAKTOR PRO 2

The Numark Mixtrack Quad

The Numark Mixtrack Quad is a 4 channel digital DJ controller with a built-in audio I/O device that was released in Spring 2013 and marketed as the only controller in its class and price range that offers 4 channel capabilities.

It is essentially a 4 channel version of the Numark Mixtrack Pro II, which is itself the second version of the infamous Mixtrack Pro, reportedly the world’s best selling digital DJ controller. With upgraded platters and touch-sensitive backlit drum pads, the Mixtrack Pro II is widely regarded as the current standard for entry level DJ controllers, so the Mixtrack Quad comes from an excellent pedigree. Numark has been producing innovative DJ equipment for 40 years, so they clearly know what they’re doing and have an enviable track record for producing both pro and consumer kit.

The Mixtrack Quad currently retails for around £210 and represents fantastic value for money. Although clearly aimed at the home DJ, it is perfect for learning how to DJ and more than up to the job for house parties and small venues. For more details about the controller itself, please see the excellent Digital DJ Tips review.

Continue reading Using the Numark Mixtrack Quad with TRAKTOR PRO 2

Mixcloud logo

How to embed your Mixcloud profile in your WordPress Blog

Mixcloud is a fantastic online music streaming service that allows you to share your DJ mixes over the internet for free. Unfortunately, most WordPress social media widgets don’t yet seem to support linking to Mixcloud profiles out-of-the-box, so for the time being you might need an alternative solution.

Here is an easy way  to embed your Mixcloud profile in a Widget Area of your WordPress Blog, for example in a sidebar or footer on every page:

  1. Log in to your WordPress Blog as an Administrator.
  2. Go to the Appearance/Widgets admin section.
  3. Choose a suitable Widget Area from those displayed down the right-hand side of the page (e.g. Main Widget Area or Secondary Widget Area). Your Widget Areas may differ depending on the WordPress Theme you are currently using.
  4. Drag and drop a new Text widget from the Available Widgets box into the correct location of your chosen Widget Area.
  5. Enter a suitable Title for the new widget. This will be displayed at the top of the new widget box, so use something like “Follow me on Mixcloud”.
  6. In a new browser window/tab, log in to your Mixcloud account and go to your profile page.
  7. Click on the Embed button.
  8. Adjust the available Options as required.
  9. Once happy with the displayed Preview, select and copy the entire contents of the HTML code box.
  10. Go back to your WordPress Appearance/Widgets window, and paste the HTML code into the main box of your newly created Text widget.
  11. Save the Text widget.
  12. Review your Blog and check that your Mixcloud profile is being displayed correctly in the chosen Widget Area.

The same approach is equally applicable to other Content Management Systems or hand-coded websites. Please bear in mind that JavaScript support is required on the client for the Mixcloud widget to display correctly.

 

How to wrap basic HTTP authentication with PHP

Suppose you have a file hosted on an Apache server that is protected by Basic HTTP Authentication, often via an old-school ‘.htaccess’ file, to prevent anonymous users from downloading it without a valid username/password. Then someone asks you to wrap that protected file download with some kind of GUI, maybe a simple HTML form to gather some standard user data (e.g. name and email address). The trouble is once the user has submitted the form they then get prompted separately by the browser to enter a username/password for the HTTP authentication, and this two step process is a bad user experience and looks unprofessional. What you really want to do is ask the user for the username and password as part of the first form, and then just supply those credentials behind the scenes so the download just starts once the form has been submitted. I was recently asked to solve this exact problem, and there simply wasn’t time to address this properly with a nicer solution.

So here is a simple way to pass in credentials for Basic HTTP Authentication from a PHP download script. You must have the PHP “Client URL Library” (“cURL”) extension installed on the web server hosting the PHP script.

If you just want to download the complete working script, you can get it from my GitHub Gist. If you’d like to read about some of the details, please continue…

Continue reading How to wrap basic HTTP authentication with PHP

How to add Google Authorship to a single author WordPress Blog

Google Authorship is a great new way to boost your online presence by associating your Google+ profile with any web content that you create, so that Google automatically displays your Google+ profile next to any of your content listed in search results. It can help you to attract new followers, and help people to easily find other content that you have produced. Google have also added new “Author Stats” to their Webmaster Tools so that authors can easily see how often their own content is being discovered in Google search results.

This post gives simple instructions on how to add Google Authorship to a WordPress Blog produced by a single author. It assumes that you are using a WordPress Theme that supports WordPress “Menus”, and that you have a menu link to an “About” page about the Blog’s main author.

  1.  Create a Google+ profile that you want to associate with the WordPress Blog in question.
  2. If you don’t already have one, register a suitable email address with the same domain name as the WordPress Blog. Note – it is still possible to associate content from a domain that you don’t have an email address for, but that is not covered by this post.
  3. Activate Google Authorship using your email address with the same domain name as your Blog.
  4. Install the AuthorSure WordPress plugin in your WordPress Blog.
  5. Follow the AuthorSure instructions for configuring a single author Blog.
  6. Ensure that you have added your Google+ profile URL to your WordPress user account profile, since this is where AuthorSure gets the Google+ profile URL from when it automatically inserts the link below every post. When logged in to your WordPress Blog as the admin user, hover over the top-right menu and click on “Edit My Profile”. At the bottom of that profile page in the “Contact Info” section you will find a space for your “Google Plus Profile URL”.
  7. Use the Google Webmaster Structured Data Testing Tool to check if your Blog has been correctly configured for Google Authorship. Paste in an example URL for a post on your Blog to see if it correctly detects your Authorship data.
  8. If this test fails, or you have any other issues, please refer to the Google Authorship help page and double check everything.

In general, it seems to take between several days and several months for your Google+ profile to start appearing next to Google search results for your content, so don’t expect immediate results.