日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2024/7/23 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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嗎?在

總結

以上是生活随笔為你收集整理的python的内置函数string_Python错误:内置函数或方法对象没有属性“StringIO”的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。