python中的google存储api放置文件问题

python中的google存储api放置文件问题,python,Python,我试图上传一个文件到谷歌存储,但我的代码冻结,没有响应。请帮帮我 霉菌代码: def PutFile(self,filename): conn = httplib.HTTPConnection("%s.commondatastorage.googleapis.com" % self.bucket) conn.set_debuglevel(2) dd = "%s" % datetime.datetime.utcnow().strftime("%a, %d %b %Y %H

我试图上传一个文件到谷歌存储,但我的代码冻结,没有响应。请帮帮我

霉菌代码:

def PutFile(self,filename):
    conn = httplib.HTTPConnection("%s.commondatastorage.googleapis.com" % self.bucket)
    conn.set_debuglevel(2)

    dd = "%s" % datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
    strToSign = "PUT\n"+"\nimage/jpeg\n"+dd+"\nx-goog-acl:public-read\n/%s/x.jpg" % self.bucket
    f = open(filename,"r")
    m = hashlib.md5()
    m.update(f.read())
    h = m.hexdigest()
    sig = base64.b64encode(hmac.new(self.secret, strToSign, hashlib.sha1).digest())
    total = os.path.getsize(filename)

    header = {"Date":dd,"x-goog-acl":"public-read","Content-MD5":h,'Content-Length':total,'Content-Type':'image/jpeg','Authorization':"GOOG1 %s:%s" % (self.key,sig)}


    r1 = conn.getresponse()
    print r1.status, r1.reason
    print r1.read()
    conn.close()

我知道这更多的是一个评论,而不是对你的问题的回答,但我把它放在一个答案中,因为我还不能评论

如果你能缩小函数中挂起它的位置,那将非常有帮助。虽然添加
print
函数/语句会稍微改变内存状态,但在这里值得一试,因为挂起的原因可能是您正在进行的网络呼叫


同样-听起来很简单,但是你确定你在网络上并且能够访问Google存储站点吗

我自己解决问题:)我的代码:

        conn = httplib.HTTPConnection("mustafa-yontar.commondatastorage.googleapis.com")
        conn.set_debuglevel(2)
        f = open(filename,"r")
        m = hashlib.md5()
        m.update(f.read())
        h = m.hexdigest()
        has = h
        dd = "%s" % datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
        strToSign = "PUT\n"+h+"\n\n"+dd+"\nx-goog-acl:public-read\n/mustafa-yontar/x.jpg"

        sig = base64.b64encode(hmac.new(self.secret, strToSign, hashlib.sha1).digest())
        total = os.path.getsize(filename)

        header = {"Date":dd,"x-goog-acl":"public-read","Content-MD5":h,'Content-Length':total,'Authorization':"GOOG1 %s:%s" % (self.key,sig)}

        conn.putrequest('PUT', "/x.jpg")
        for h in header:
            conn.putheader(h, header[h])
        conn.endheaders()
        bytess = open('x.jpg', 'rb').read()
        f = StringIO(bytess)
        f.seek(0)


        while True:
            bytes = f.read(1024)
            if not bytes: break

            length = len(bytes)
            conn.send('%X\r\n' % length)
            conn.send(bytes + '\r\n')
        conn.send('0\r\n\r\n')

        #errcode, errmsg, headers = conn.getresponse()
        #h.close()


        #conn.request("PUT","/mustafa-yontar/x.jpg",f.read(),header)
        r1 = conn.getresponse()
        print r1.status, r1.reason
        print r1.read()
        conn.close()
        print has

它在哪一行冻结?r1=conn.getresponse()行冻结我正在访问google存储站点并获取方法没有问题。是否可以从HTTP连接获取更详细的输出?可能是通过抛出详细或日志标记?您还可以让WireShark这样的网络分析器尝试在运行程序/脚本时查看机器的实际运行情况。我看到http analayzer发出请求,我看到等待响应。我正在添加到我的输出截图我现在看到了截图。老实说,破译这是我的经验之外,希望有人会看到它现在虽然!