<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Code Spatter - Latest Comments in Getting Basecamp API Working with Python</title><link>http://codespatter.disqus.com/</link><description></description><atom:link href="https://codespatter.disqus.com/getting_basecamp_api_working_with_python/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Sun, 17 Jan 2010 05:36:44 -0000</lastBuildDate><item><title>Re: Getting Basecamp API Working with Python</title><link>http://codespatter.com/2009/04/01/getting-basecamp-api-working-with-python/#comment-30079974</link><description>&lt;p&gt;I couldn't get this code running.&lt;br&gt;But I stumbled upon a working &lt;a href="http://basecamp.py" rel="nofollow noopener" target="_blank" title="basecamp.py"&gt;basecamp.py&lt;/a&gt; - it's part of the basecampreporting library (&lt;a href="http://github.com/cmheisel/basecampreporting/)" rel="nofollow noopener" target="_blank" title="http://github.com/cmheisel/basecampreporting/)"&gt;http://github.com/cmheisel/...&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;According to Chris Heisel, the author of basecampreporting, the reason why the original &lt;a href="http://basecamp.py" rel="nofollow noopener" target="_blank" title="basecamp.py"&gt;basecamp.py&lt;/a&gt; is not working properly is the use of base64. When you encode a string with base64, it adds a newline at the end of the encoded string. The newline is what irritates basecamp. Get rid of the newline, and &lt;a href="http://basecamp.py" rel="nofollow noopener" target="_blank" title="basecamp.py"&gt;basecamp.py&lt;/a&gt; works.&lt;/p&gt;&lt;p&gt;This is how Chris Heisel did it (again around line 64):&lt;/p&gt;&lt;p&gt;    def __init__(self, baseURL, username, password):&lt;br&gt;        self.baseURL = baseURL&lt;br&gt;        if self.baseURL[-1] == '/':&lt;br&gt;            self.baseURL = self.baseURL[:-1]&lt;/p&gt;&lt;p&gt;        self.opener = urllib2.build_opener()&lt;/p&gt;&lt;p&gt;        self.auth_string = '%s:%s' % (username, password)&lt;br&gt;        self.encoded_auth_string = base64.encodestring(self.auth_string)&lt;/p&gt;&lt;p&gt;        #Python 2.5, at least on Ubuntu is adding a newline when encoding,&lt;br&gt;        #which Basecamp chokes on and returns an HTTP 400&lt;br&gt;        self.encoded_auth_string = self.encoded_auth_string.replace('\n', '')&lt;br&gt;        self.headers = [&lt;br&gt;            ('Content-Type', 'application/xml'),&lt;br&gt;            ('Accept', 'application/xml'),&lt;br&gt;            ('Authorization', 'Basic %s' % self.encoded_auth_string), ]&lt;br&gt;        self.opener.addheaders = self.headers&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Benjamin Buch</dc:creator><pubDate>Sun, 17 Jan 2010 05:36:44 -0000</pubDate></item><item><title>Re: Getting Basecamp API Working with Python</title><link>http://codespatter.com/2009/04/01/getting-basecamp-api-working-with-python/#comment-21728747</link><description>&lt;p&gt;Is this code still working for you?  I made your changes but basecamp dumps me into the login page now.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Greg</dc:creator><pubDate>Mon, 02 Nov 2009 23:03:01 -0000</pubDate></item></channel></rss>