Python Google Drive Api限制下载速度

2024-04-25 11:42:07 发布

您现在位置:Python中文网/ 问答频道 /正文

下载文件从谷歌驱动器没有问题。我需要限制下载速度像512kbps,1024kbps每秒。你知道吗

试图时间。睡眠(1) 改变大小,但效果并不理想。也许有限制速度的作用。你知道吗

        http = credentials.authorize(httplib2.Http())
        drive_service = discovery.build('drive', 'v3', http=http, cache_discovery=False)
        request = drive_service.files().get_media(fileId=link)


        file = drive_service.files().get(fileId=link).execute()
        dosyadi = file['name']
        fh = io.FileIO(yazilacakyer, 'wb')
        downloader = MediaIoBaseDownload(fh, request, chunksize=1024 * 1024)
        time1 = time.time()
        done = False

        while done is False:
            status, done = downloader.next_chunk()
            fark = float(time.time() - time1)
            time1 = time.time()
            print('Download Speed:')
            print(self.byteToKb_or_Mb(int(1024/fark)*1024))

Tags: falsehttpgettimerequestservicelinkfiles
1条回答
网友
1楼 · 发布于 2024-04-25 11:42:07

不确定您想要实现什么,但也许最好使用http标准中的range-request头,而不是使用带宽。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests

例如,添加header Range:bytes=0-1023将使服务器仅返回该数据块。你知道吗

以后您可以使用多线程来同时提取多个块。你知道吗

相关问题 更多 >

    热门问题