質問

My app use urllib2 to fetch remote http file. But it does not fetch the whole file, it just read 5 bytes from it. I purposely do that to save quota. As the line 'content = remoteFileFh.read(5)' below does.

def httpGetFile(self,remoteFile):    
    print 'downloading %s...'%remoteFile,
    remoteFileFh = urllib2.urlopen(remoteFile)
    content = remoteFileFh.read(5)
    print 'content:%s' % content
    remoteFileFh.close()
    print 'done.'

But it seems it still consume 'Incoming Bandwidth' as soon as fetching the whole file. Why? how Google host service calculate that?

役に立ちましたか?

解決

The URLfetch service doesn't support fetching partial content. On App Engine, urllib2 is just a wrapper over urlfetch, so the whole response is fetched and made available to your application whether you read it all or not.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top