Sohaib
Sohaib

Reputation: 4704

Using boto in python 3

I have the boto 2.3.0 neo branch and python 3.3. I used boto to collect data from simpledb and it worked fine. However now when I try boto to connect to s3 I get errors. Can anyone please guide me in the right direction. I really dont want to downgrade my python cause my whole project is in python 3.3.

Here is the list of commands I wrote:

       >>> from boto.s3.key import Key
       >>> k = Key(bucket)
       >>> k.key='testfile'
       >>> k.set_contents_from_string('Hello this is my Boto S3 Test')

An here is the list of errors I get on executing the last command:

       Traceback (most recent call last):
       File "<pyshell#8>", line 1, in <module>
       k.set_contents_from_string('Hello this is my Boto S3 Test')
       File "C:\Python33\lib\site-packages\boto\s3\key.py", line 1060, in              
       set_contents_from_string
       fp = compat.StringIO(s)
       TypeError: initial_value must be str or None, not bytes

The other problems I have been having (root is the same I guess) are given at this link:

iter() returned non-iterator of type 'Key' : boto amazon s3

Upvotes: 2

Views: 3975

Answers (4)

Zulu
Zulu

Reputation: 9285

Actually boto can run in Python 3.

Set:

Upvotes: 1

Nick
Nick

Reputation: 21

I had the exact same problem, and wrote a small python package to solve it. This will let you make a python2 virtualenv, and seamlessly import the boto packages into your python3 package.

Alternatively, you could do a system install of awscli (which uses python2, as it's based on boto) but then invoke it via subprocess.check_call().

Upvotes: 0

meawoppl
meawoppl

Reputation: 2802

This problem looks like a StringIO vs BytesIO problem. Check out here for a lead:

https://docs.python.org/2/library/io.html

Upvotes: 0

DR1979
DR1979

Reputation: 1

Yeah, short answer...you'll have to refactor, which isn't necessarily a bad thing because this should be ported to 3. Try running 2to3 on the sources and building with Python3...Address any issues that come up in the build process...there'll be less to deal with than the answer above if you're using a lot of boto functionality in your project.

Upvotes: 0

Related Questions