June 07, 2009
Python Authentication :) This post is outdated
So I am having some issues logging in and using the api. I can use the api with curl no problem: curl -u API:PASS http://some-shop.myshopify.com/admin/collects.xml and I get back the xml for the collections!!!! Awesome right, well kinda :) So I am trying to use python to build my app, but I keep getting an authentication required error while using urllib2. I have setup my HTTPPasswordMgrWithDefaultRealm and it just fails to authenticate. So I did a little digging and constructed the http header on my own with the base64 encoded string from curl. (captured with a proxy) Authentication worked! So I tried to just base64 encode my api key and secret with base64.encodestring and for some reason there are '\n' in my encoded string. If I remove the newlines it will authenticate. I have no idea why this is happening I did some digging around the internet and found nothing. I figured I would just post here my findings so if anyone else is using python they won't waste an afternoon doing something that should be simple :) I have read the python documentation on base64 and they mention the encoded string ending in \n but I am finding them in the string. I bet this is why urllib2 won't work with the password manager.