<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>Death of a Gremmie</title>
    <link>http://deathofagremmie.com</link>
    <description>Brian Neal's blog about programming.</description>
    <pubDate>Sun, 13 May 2012 18:30:33 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Mounting a Synology DiskStation on Ubuntu 12.04</title>
      <link>http://deathofagremmie.com/2012/05/01/mounting-a-synology-diskstation-on-ubuntu-12.04</link>
      <pubDate>Tue, 01 May 2012 20:45:00 CDT</pubDate>
      <category><![CDATA[Ubuntu]]></category>
      <category><![CDATA[Synology]]></category>
      <category><![CDATA[Linux]]></category>
      <guid isPermaLink="true">http://deathofagremmie.com/2012/05/01/mounting-a-synology-diskstation-on-ubuntu-12.04</guid>
      <description>Mounting a Synology DiskStation on Ubuntu 12.04</description>
      <content:encoded><![CDATA[<div class="document">
<p>I have a Synology DiskStation that I use for a home NAS. I didn't take good
notes when I got it to work with Ubuntu 10.04, so I had to fumble about when I
upgraded to Ubuntu 12.04 last weekend. So for next time, here is the recipe I
used.</p>
<p>First, you need to install the <strong>cifs-utils</strong> package:</p>
<pre class="literal-block">
$ sudo apt-get install cifs-utils
</pre>
<p>Next, I added the following text to my <tt class="docutils literal">/etc/fstab</tt> file:</p>
<pre class="literal-block">
//192.168.1.2/shared /mnt/syn cifs noauto,iocharset=utf8,uid=1000,gid=1000,credentials=/home/brian/.cifspwd 0 0
</pre>
<p>Take note of the following:</p>
<ul class="simple">
<li>Replace <tt class="docutils literal">//192.168.1.2/</tt> with the IP address or hostname of your
DiskStation. Likewise, <tt class="docutils literal">/shared</tt> is just the path on the DiskStation that I
wanted to mount.</li>
<li><tt class="docutils literal">/mnt/syn</tt> is the mount point where the DiskStation will appear on our local
filesystem.</li>
<li>I didn't want my laptop to mount the DiskStation on bootup, so I used the
<tt class="docutils literal">noauto</tt> parameter.</li>
<li>The <tt class="docutils literal">uid</tt> and <tt class="docutils literal">gid</tt> should match the user and group IDs of your Ubuntu
user. You can find this by grepping your username in <tt class="docutils literal">/etc/passwd</tt>.</li>
<li>The <tt class="docutils literal">credentials</tt> parameter should point to a file you create that contains
the username and password of the DiskStation user you want to impersonate (see
below).</li>
</ul>
<p>Your <tt class="docutils literal">.cifspwd</tt> file should look like the following:</p>
<pre class="literal-block">
username=username
password=password
</pre>
<p>Obviously you'll want to use the real username / password pair of a user on your
DiskStation.</p>
<p>To be paranoid, you should make the file owned by root and readable only by
root. Do this after you get everything working:</p>
<pre class="literal-block">
$ sudo chown root:root .cifspwd
$ sudo chmod 0600 .cifspwd
</pre>
<p>I created the mount point for the DiskStation with:</p>
<pre class="literal-block">
$ sudo mkdir -p /mnt/syn
</pre>
<p>Then, whenever I want to use the DiskStation I use:</p>
<pre class="literal-block">
$ sudo mount /mnt/syn
</pre>
<p>And to unmount it:</p>
<pre class="literal-block">
$ sudo umount /mnt/syn
</pre>
<p>You can avoid the <tt class="docutils literal">mount</tt> and <tt class="docutils literal">umount</tt> commands if you remove the
<tt class="docutils literal">noauto</tt> parameter from the <tt class="docutils literal">/etc/fstab</tt> entry. In that case, Ubuntu will
automatically try to mount the DiskStation at startup.</p>
</div>
]]></content:encoded>
    </item>
    <item>
      <title>Django Uploads and UnicodeEncodeError</title>
      <link>http://deathofagremmie.com/2011/06/04/django-uploads-and-unicodeencodeerror</link>
      <pubDate>Sat, 04 Jun 2011 20:00:00 CDT</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[Linux]]></category>
      <category><![CDATA[Unicode]]></category>
      <category><![CDATA[Django]]></category>
      <guid isPermaLink="true">http://deathofagremmie.com/2011/06/04/django-uploads-and-unicodeencodeerror</guid>
      <description>Django Uploads and UnicodeEncodeError</description>
      <content:encoded><![CDATA[<div class="document">
<p>Something strange happened that I wish to document in case it helps others.  I
had to reboot my Ubuntu server while troubleshooting a disk problem. After the
reboot, I began receiving internal server errors whenever someone tried to view
a certain forum thread on my <a class="reference external" href="http://djangoproject.com">Django</a> powered website. After some detective work,
I determined it was because a user that had posted in the thread had an avatar
image whose filename contained non-ASCII characters. The image file had been
there for months, and I still cannot explain why it just suddenly started
happening.</p>
<p>The traceback I was getting ended with something like this:</p>
<div class="highlight"><pre><span class="n">File</span> <span class="s">&quot;/django/core/files/storage.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">159</span><span class="p">,</span> <span class="ow">in</span> <span class="n">_open</span>
<span class="k">return</span> <span class="n">File</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> <span class="n">mode</span><span class="p">))</span>

<span class="ne">UnicodeEncodeError</span><span class="p">:</span> <span class="s">&#39;ascii&#39;</span> <span class="n">codec</span> <span class="n">can</span><span class="s">&#39;t encode characters in position 72-79: ordinal not in range(128)</span>
</pre></div>
<p>So it appeared that the <tt class="docutils literal">open()</tt> call was triggering the error. This led me on
a twisty Google search which had many dead ends. Eventually I found a suitable
explanation. Apparently, Linux filesystems don't enforce a particular Unicode
encoding for filenames. Linux applications must decide how to interpret
filenames all on their own. The Python OS library (on Linux) uses environment
variables to determine what locale you are in, and this chooses the encoding for
filenames.  If these environment variables are not set, Python falls back to
ASCII (by default), and hence the source of my <tt class="docutils literal">UnicodeEncodeError</tt>.</p>
<p>So how do you tell a Python instance that is running under Apache / <tt class="docutils literal">mod_wsgi</tt>
about these environment variables? It turns out the answer is in the <a class="reference external" href="https://docs.djangoproject.com/en/1.3/howto/deployment/modpython/#if-you-get-a-unicodeencodeerror">Django
documentation</a>, albeit in the <tt class="docutils literal">mod_python</tt> integration section.</p>
<p>So, to fix the issue, I added the following lines to my <tt class="docutils literal">/etc/apache2/envvars</tt>
file:</p>
<div class="highlight"><pre><span class="nb">export </span><span class="nv">LANG</span><span class="o">=</span><span class="s1">&#39;en_US.UTF-8&#39;</span>
<span class="nb">export </span><span class="nv">LC_ALL</span><span class="o">=</span><span class="s1">&#39;en_US.UTF-8&#39;</span>
</pre></div>
<p>Note that you must cold stop and re-start Apache for these changes to take
effect. I got tripped up at first because I did an <tt class="docutils literal">apache2ctrl
graceful</tt>, and that was not sufficient to create a new environment.</p>
</div>
]]></content:encoded>
    </item>
  </channel>
</rss>

