python script is not running without sudo - why?
<p>This is my python script which downloads the most recent image from my S3 bucket. When I run this script using <code>sudo python script.py</code> it does as expected, 
but not when I run it as <code>python script.py</code>. In this case, the script finishes cleanly without exceptions or process lockup, but there is no image file.</p>

<p>Why does this happen? Is there something I could do at boto's library end or any other thing?</p>

<pre><code>import boto
import logging


def s3_download():
    bucket_name = 'cloudadic'
    conn = boto.connect_s3('XXXXXX', 'YYYYYYY')
    bucket = conn.get_bucket(bucket_name)

    for key in bucket.list('ocr/uploads'):
        try:
            l = [(k.last_modified, k) for k in bucket]
            key = sorted(l, cmp=lambda x, y: cmp(x[0], y[0]))[-1][1]
            res = key.get_contents_to_filename(key.name)
        except:
            logging.info(key.name + ":" + "FAILED")

if __name__ == "__main__":
     s3_download()
</code></pre>

<p>Always install <a href="https://virtualenv.pypa.io/en/stable/" rel="nofollow">virtual environment</a> before you start development in python. </p>

<p>The issue you face is typical python newbie problem : use <code>sudo</code> to install all the pypi package. </p>

<p>When you do <code>sudo pip install boto3</code>, it will install pypi package to system workspace and only accessible by <code>sudo</code>. In such case, <code>sudo python script.py</code> will works, because it has the rights to access the package.</p>

<p>To resolve this issues and isolation of development environment (so you don't pollute different project with differnt pypi package), python developer will install python virtual environment (from above link), then use <code>mkvirtualenv</code> to create your project workspace, run <code>pip install</code> and <code>python setup.py install</code> to install required package to the environment, then you can run python without the <code>sudo python</code>.</p>

<p>Python virtualenv is also deployed inside production environment for the same reason.</p>

<p><strong>Important Note</strong> : avoid boto and boto2. AWS no longer support them nor with bug fixing(AWS is not officially support boto2, use it at your own risk). Switch to boto3.  </p>

<hr>

<p>For the exceptional handling issues, @Yann Vernier has mentioned it. And exception error will not logged by <code>logging.info</code>.  You may try with <code>logging.debug</code> or simple use <code>raise</code> to raise the actual exception error.</p>

python boto sudo