gtk 与 Amazon S3 冲突的问题。。。 急

hispania 2010-11-15 05:02:20
客户端的界面是用gtk 写的,但是在和S3交互的时候,一直报错,经过调试,发现只有在将 import gtk 注释掉的情况下才能和S3交互成功。。。但是这样的话,界面就无法显示。请高人解答。。。急!

代码如下:
import sys
import pygtk
import CloudSync -------------------------------------------> 这是与S3的交互模块
import face_1_test ------------------------------------------ >这是主界面模块
import gtk ------------------------------------------ >只有把这句话注释掉,才能交互成功,但是会导致界面无法显示
import xml.etree.ElementTree as ET

class landing_face:

def __init__(self):
builder=gtk.Builder()
builder.add_from_file("landing.glade")
self.landing_window=builder.get_object("landing_window")

#entry
self.entry_user=builder.get_object("entry_user")
self.entry_code=builder.get_object("entry_code")
self.entry_code.set_visibility(False)

#button
self.button_land=builder.get_object("button_land")
self.button_quit=builder.get_object("button_quit")
self.entry_code.connect("activate",self.on_landing) #combine <enter>


#connect_signals
connect_landing_face={"on_landing_face_destroy":gtk.main_quit,
"on_landing":self.on_landing,
"on_quit":self.on_quit
}

builder.connect_signals(connect_landing_face)

def on_landing(self,action):
string_user = self.entry_user.get_text()
string_code = self.entry_code.get_text()
query_id = "WKy3rMzOWPouVOxK1p3Ar1C2uRBwa2FBXnCw"
secret_key = "uKDWFs7Ul6OicBEZUE5sCYycnHcTedCMMsxqQ"
host = "10.3.1.124"
test = CloudSync.CloudSync(query_id, secret_key, True, host)
test.prepareSync()
landing_id = test.serviceID
landing_code = test.serviceKey

if string_user == landing_id and string_code == landing_code:
file_object = open('/python_object/onConfig_SyncFolder.xml')
try:
all_text = file_object.read()
finally:
file_object.close()
test.saveSyncConfig(file_object)
print "landing success!"
self.landing_window.hide()
edit = face_1_test.face_1()
edit.main_window.show()

else:
landing_dlg=gtk.Dialog("name or code wrong",self.landing_window,gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
label = gtk.Label("fail,please try again ")
landing_dlg.vbox.pack_start(label)
label.show()
response = landing_dlg.run()
if response == gtk.RESPONSE_ACCEPT:
landing_dlg.destroy()
self.entry_user.set_text("")
self.entry_code.set_text("")
print "please try again!"

def on_quit(self,action):
gtk.main_quit()

if __name__=="__main__":
edit = landing_face()
edit.landing_window.show()
gtk.main()

与S3交互的代码如下:
#!/usr/bin/python
import boto
from boto.s3.connection import S3Connection
from boto.s3.key import Key
class CloudSync:
'''Represents a synchronization entity.'''
def __init__(self, serviceID, serviceKey, is_walrus=False, serviceEndpoint='s3.amazonaws.com'):
'''
Initializes the data.
'''
# service ID and Key used to obtain a s3/walrus connection
self.serviceID = serviceID
self.serviceKey = serviceKey

# the server address
self.serviceEndpoint = serviceEndpoint

# whether this connection is based on walrus
self.is_walrus = is_walrus

# the S3/Walrus Connection
self.connection = None

# Bucket Name, represents the bucket where the sync data is stored
self.bucketName = "neocloudsync_sun"
self.bucket = None

# User's device Name. All the user's content have prefix <deviceName>.
self.deviceName="device1"

# AutoSync's folder Name
self.folderName="neoAutoSync/"

# Config file Name(Stored on cloud storage server)
self.configFilename="neosync_config.xml"

# Content of configuration (List)
self.syncConfig = None

# the file name of the bookmark need to be synchronized
self.fileBookmark = None

# the file in sync operation
self.fileSyncCurrent = None

# list of files which need to be synchronized
self.fileSyncNeeded = None

# list of files which get synchronized
self.fileSyncDone = None

def prepareSync(self):
'''some preparation before sync'''
self.obtainConn()
self.checkSyncFolder()

def obtainConn(self):
'''
Get connection to Cloud Storage Server.
Called at initialization
'''
try:
if(self.is_walrus):
self.obtainConn_walrus()
else:
self.connection = S3Connection(self.serviceID, self.serviceKey)
except Exception as e:
print("Cannot get a connection to storage server. \nDetails: %s\n" % e)
#ccInfo-Done

def obtainConn_walrus(self):
'''
Used by self.getConnection() to get
connection to Walrus Cloud Storage Server.
'''
calling_format=boto.s3.connection.OrdinaryCallingFormat()
self.connection = boto.s3.connection.S3Connection(aws_access_key_id=self.serviceID,
aws_secret_access_key=self.serviceKey,
is_secure=False,
host=self.serviceEndpoint,
port=8773,
calling_format=calling_format,
path="/services/Walrus")
#ccInfo-Done


def checkSyncFolder(self):
'''
Called at initialization to ensure the existence of sync bucket and folder
Check the bucket and folder used by neoShine cloud sync system,
if the required bucket and folder do not exist, try to create them,
if something error, return False else return True
'''
try:
if(not self.bucketName.islower()):
print("Bucket name Uppercase not allowed, convert to lower")
self.bucketName = self.bucketName.lower()
b = self.connection.lookup(self.bucketName)
except Exception as e:
print("Error.\nDetails: %s" % e)
if(b==None):
print("bucket does not exits, trying to create it")
try:
self.bucket = self.connection.create_bucket(self.bucketName)
print("Bucket created successfully")
except Exception as e:
print("Cannot create a bucket.\nDetails: %s" % e)
return False
else:
self.bucket = b
print("bucket name is: %s" % b)

# create the sync folder
k = Key(self.bucket)
k.key = self.folderName
try:
k.set_contents_from_string('')
return True
except Exception as e:
print("Cannot create folder for sync: %s.\n Details: %s" % (fileName,e))
return False
#ccInfo-Done

def getSyncStatus(self):
try:
f = self.bucket.get_all_keys()
for ff in f:
#s = ff.get_metadata('md5-hash')
print ff
except Exception as e:
print("Cannot get the bucket. \nDetails: %s\n" % e)

def zz_addSyncItems(self):
print("This is addSyncItems!")
def zz_removeSyncItems():
print("This is removeSyncItems!")

def getSyncConfig(self):
'''
Get sync config file from cloud storage server to a local string
'''
k = Key(self.bucket) # Specify which bucket to use
k.key = self.configFilename # The key's name
try:
str = k.get_contents_as_string()
self.syncConfiguration = str
return str
#print("The content of Config file is: %s, size: %s" % (str,k.size))
###########################
# Call self.parseSyncFiles
###########################
#return self.syncConfiguration
except Exception as e:
print("Cannot get file: %s\n Details: %s" % (k.key, e))

def saveSyncConfig(self, configStr):
'''
Save sync config string to cloud storage server
'''
k = Key(self.bucket) # Specify which bucket to use
k.key = self.configFilename # The key's name
try:
k.set_contents_from_string(configStr)
except Exception as e:
print("Cannot save to Server!\n Details: %s" % (e))
return 1
return 0

def zz_sync2Server():
print("This is sync2Server!")

def __del__(self):
'''I am dying.'''
print("This is the del method")

# Below is some methods for Debug
def sysInfo(self):
if(self.is_walrus):
print("This is a Walrus Connection!")
else:
print("This is a S3 Connection!")
报的错误如下显示:
Warning: failed to parse error message from AWS: <unknown>:1:0: syntax error
bucket does not exits, trying to create it
Warning: failed to parse error message from AWS: <unknown>:1:0: syntax error
Cannot create a bucket.
Details: S3ResponseError: 403 Forbidden
Failure: 403 Forbidden
Unable to parse date.


Cannot save to Server!
Details: 'NoneType' object has no attribute 'connection'
=========================================================

希望有好心人能够帮下忙,QQ是:330695846.
如果对代码中有不明白的地方,可以加我QQ。。。。 再次拜谢了。

哎,为啥gtk 会和 S3 冲突啊。。。。。。。。。

...全文
235 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文针对考虑算力负荷时空迁移特性的多微电网与共享储能系统的协同优化调度问题展开研究,并提供了完整的Matlab代码实现。研究构建了融合算力负荷动态迁移特征的数学优化模型,通过引入共享储能机制,实现多微电网间的能量互济与资源协同,有效提升系统对分布式能源波动性和负荷不确定性的适应能力。文中采用先进的优化算法求解该调度模型,重点解决了算力任务在时空维度上的灵活调配与电力供需平衡之间的耦合关系,旨在提高综合能源系统的运行经济性、可靠性与灵活性。所提出的方法为未来能源互联网背景下电-算协同管理提供了理论支持与技术路径。; 适合人群:具备电力系统分析、优化理论基础及Matlab编程能力的科研人员、高校研究生,尤其适用于从事微电网运行、共享储能配置、综合能源系统优化以及电-算融合等领域研究的专业技术人员。; 使用场景及目标:①开展多微电网与共享储能系统的协同调度策略设计与仿真验证;②支撑高比例可再生能源接入下的新型电力系统优化运行研究;③为考虑算力迁移的数据中心与电网协同调度提供建模与算法参考;④作为高水平学术论文撰写或学位课题研究的技术支撑与代码复现平台。; 阅读建议:建议读者结合Matlab代码与相关学术文献深入研读,重点关注目标函数构建、约束条件设定及求解器调用逻辑,可在现有模型基础上拓展多时间尺度优化、不确定性建模(如鲁棒优化、随机规划)或加入实际工程约束进行二次开发与深化研究。

37,738

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧