python的内置函数string_Python错误:内置函数或方法对象没有属性“StringIO”

我只想下载一张图片。然后上传到Amazon S3。但它不起作用。在'builtin_function_or_method' object has no attribute 'StringIO'

Traceback (most recent call last):

File "flickrDump.py", line 16, in

imgpath = s3.upload_thumbnail(thumbnail_name=tools.randomString(10), thumbnail_data=tdata,bucket="fabletest")

File "../lib/s3.py", line 52, in upload_thumbnail

k.set_contents_from_string(thumbnail_data)

File "/usr/lib/pymodules/python2.6/boto/s3/key.py", line 539, in set_contents_from_string

self.set_contents_from_file(fp, headers, replace, cb, num_cb, policy)

File "/usr/lib/pymodules/python2.6/boto/s3/key.py", line 455, in set_contents_from_file

self.send_file(fp, headers, cb, num_cb)

File "/usr/lib/pymodules/python2.6/boto/s3/key.py", line 366, in send_file

return self.bucket.connection.make_request('PUT', self.bucket.name,

AttributeError: 'str' object has no attribute 'connection'

我下载和上传的代码是:

^{pr2}$

我使用的库是s3库。我在某个地方下载的,所以应该是标准的。在from boto.s3.connection import S3Connection

from boto.s3.key import Key

from boto.s3.bucket import Bucket

import datetime

ACCESSKEY = 'MYKEY'

SECRETKEY = 'MYSECRET'

def get_bucket_path(bucket,filename,https=False):

path = None

if isinstance(bucket, Bucket):

path = bucket.name

else:

path = bucket

if https:

return "https://s3.amazonaws.com/%s/%s" % (path, filename)

else:

return "http://s3.amazonaws.com/%s/%s" % (path, filename)

def _aws_keys():

return ACCESSKEY, SECRETKEY

def _conn():

key,secret = _aws_keys()

return S3Connection(key,secret)

def cache_bucket(conn = _conn()):

bucket = conn.create_bucket('mimvicache') bucket.make_public()

return bucket

class AwsException(Exception):

def __init__(self,value):

self.errorval = value

def __str__(self):

return repr(self.errorval)

def upload_thumbnail(thumbnail_name,thumbnail_data=None,thumbnail_path=None,bucket=cache_bucket

(),conn=_conn(),notes=None,image_id=None):

k = Key(bucket)

k.key = thumbnail_name

if notes is not None:

k.set_metadata("notes",notes)

if image_id is not None:

k.set_metadata("image_id",image_id)

if thumbnail_data is not None:

k.set_contents_from_string(thumbnail_data)

elif thumbnail_path is not None:

k.set_contents_from_filename(thumbnail_path)

else:

raise AwsException("No file name")

k.set_acl('public-read')

return get_bucket_path(bucket.name,k.key)

有人能帮我把这个图片上传到S3吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值