我正在尝试使用Python将文件上传到Google云存储桶。之前运行正常,但突然返回错误。
这是我的代码:
来自views.py:
def perform_upload(video, thumbnail):
print('vdieo name is: {}'.format(video))
servise = discovery.build('storage', 'v1', credentials=credentials)
bucket_name = 'test_bucket004'
print('Uploading the video...')
media = MediaFileUpload(video, chunksize=4149304, mimetype='video/mp4',
resumable=True)
req = servise.objects().insert(
bucket=bucket_name,
name=str(video),
media_body=media,
body={"cacheControl": "public,max-age=31536000"},
predefinedAcl='publicRead'
)
resp = None
while resp is None:
status, resp = req.next_chunk()
print(resp)
返回的内容如下:
BrokenPipeError:[Errno 32]管道损坏
[22 / Sep / 2018 04:56:50]“ POST / api / convert / HTTP / 1.1” 500 15981
和回溯指向此行:
status, resp = req.next_chunk()
有什么事吗
我该如何解决管道破裂的错误?
提前致谢!
最佳答案
当您的网络连接(因此,您与GCS的连接)由于某种原因不稳定时,就会发生这种情况。我建议从具有更稳定Internet连接的环境中重试此操作(从wifi切换到有线连接,删除中间代理或防火墙等)。
关于python - 将Python文件上传到Google Cloud Storage Bucket返回管道中断错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52453654/