开发者

How to compile python code that uses boto to access S3?

I'm trying to compile a simple Python program, that uploads files to an S3 bucket using the boto package, in to a single, redistributable .exe file. I'm open to any compilation method. So far I've tried both bbfreeze and py2exe and both yield the same results. The code in question that causes trouble looks like this:

import boto
#...snip...
fname_base = os.path.basename(fname)
s3 = boto.connect_s3(aws_access_key_id=_aws_key, aws_secret_access_key=_aws_secret_key, is_secure=False);
bucket = s3.get_bucket(_bucket)
key = bucket.new_key(fname_base)
key.set_contents_from_filename(fname)

Compiled with either executable bundling utility and run I get:

Traceback (most recent call last):
  File "s3stash.py", line 238, in <module>
    sys.exit(main())
  File "s3stash.py", line 225, in main
    push_file_to_s3(f, options)
  File "s3stash.py", line 160, in push_file_to_s3
    _push_with_boto(fname)
  File "s3stash.py", line 148, in _push_with_boto
    s3 = boto.connect_s3(aws_access_key_id=_aws_key, aws_secret_access_key=_aws_secret_key, is_secure=False);
  File "boto\__init__.pyo", line 104, in connect_s3
  File "zipextimporter.pyo", line 82, in load_module
  File "boto\s3\connection.pyo", line 27, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "boto\utils.pyo", line 55, in <module>
  File "email\__init__.pyo", line 79, in __getattr__
ImportError: No module named multipart

I'm using ActiveState Python 2.6 on Windows XP SP3. The boto package was installed with:

easy_instal开发者_运维知识库ler --always-unzip boto

I used the --always-unzip option based on the information found here about py2exe having issues with the egg files that were unpacked. Unfortunately the error I get is the same when I use bb-freeze to build the executable.

The output from py2exe includes, near the end, the following bit of information:

The following modules appear to be missing
['_scproxy', 'email.Encoders', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'simplejson']

Which lends some hints. I tried methods suggested in other posts to SO where the -i option was recommended when compiling with py2exe and unfortunately nothing helped. In those other questions the users were doing their own explicit inclusion of of the email sub-modules. I could not figure how to adapt those solutions to my case unfortunately and just adding them with -i didn't stop py2exe from warning me of the missing modules, or the resulting bundled exe from failing with the missing module error.

Can someone help me get this code bundled for redistribution?


I actually got this to work. The answer was to ditch boto and use the poster library instead. I still use boto to generate a signed policy and the necessary form fields for POST I do via poster, but the actual executable that does the POST only includes poster now. With just poster in the mix, py2exe doesn't have any issues creating a standalone executable for me for redistribution.


I know this is an old question, but I had the same problem and fixed it while still using py2exe and py2app. Just use the 'packages' option instead of the 'includes' option in your setup.py:

extra = {}
mainscript = "foo/__main__.py"

if is_os_x():
    extra["setup_requires"] =['py2app']
    extra["app"] = [mainscript]
    extra["options"] = { "py2app": {
        "packages": ['email'],
        }                                       
    }

elif is_windows():
    extra["setup_requires"] =['py2exe']
    extra['console'] = [mainscript]
    extra['options'] = {'py2exe': {
        # Includes that py2exe doesn't include automatically
       'packages': ['email'],
       }
    }

setup(
    # snip
    ** extra
)   

Hope that helps.


I've managed to create working exe with boto & py2exe

Add to your script.py

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

Next error is with HTTPS connection, it seems that py2exe is "hiding" cert file somehow.. The way to fix this is 1) use HTTP OR 2) dont check certs

1) HTTP

conn = boto.connect_dynamodb(
    aws_access_key_id = ' ',
    aws_secret_access_key = ' ', 
    is_secure = False)

"is_secure = False" is crutial

2) DONT CHECK CERTS

conn = boto.connect_dynamodb(
    aws_access_key_id = ' ',
    aws_secret_access_key = ' ', 
    is_secure = True, 
    validate_certs = False)

"validate_certs = False" is crutial

If someone figures out how to fix error in cert validation, please reply !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜