http://ecommerce.shopify.com/c/shopify-apps/t/python-authentication-27662 explains more. It looks urllib2 needs a WWW-Authenticate header in the initial 401 response from the server before it will attempt authentication (which is the HTTP standard). I guess that Apache doesn't use this standard - at least on my machine - which means that it never tries to use the opener.