如何使用python将JSON上传到google云存储
我正在尝试加载此代码,以便通过python将json上传到我的google云如何使用python将JSON上传到google云存储,python,json,upload,blob,google-cloud-storage,Python,Json,Upload,Blob,Google Cloud Storage,我正在尝试加载此代码,以便通过python将json上传到我的google云 import boto import gcs_oauth2_boto_plugin import os import shutil import StringIO import tempfile import time from google.cloud import storage from google.cloud.storage import blob client = storage.Client(proj
import boto
import gcs_oauth2_boto_plugin
import os
import shutil
import StringIO
import tempfile
import time
from google.cloud import storage
from google.cloud.storage import blob
client = storage.Client(project='dataworks-356fa')
bucket = client.get_bucket('dataworks-356fa-backups')
blob = ('t.json', bucket)
with open('t.json', 'rb'):
blob.upload_from_file('t.json')
我正在遵循关于
我被困住了,不知道去哪里,所以任何帮助都将不胜感激。我已经用
blob.upload('t.json')
更改了\u文件('t.json')中的blob.upload('t.json')
,得到了相同的问题 看起来您试图使用类Blob的实例,但错误地使用了元组。试试这个:
client = storage.Client(project='dataworks-356fa')
bucket = client.get_bucket('dataworks-356fa-backups')
blob = bucket.blob('t.json')
with open('t.json', 'rb') as json_file:
blob.upload_from_file(json_file)
请在此处发布错误代码。
upload\u from\u file
方法以file object
为参数,将文件名传递给upload\u from\u file
方法。回溯(最后一次调用):文件“uploadcloud.py”,第16行,在blob中。upload\u from\u file('t.json'))AttributeError:“tuple”对象没有“upload\u from\u file”回溯属性(上次调用):文件“uploadcloud.py”,第16行,在blob.upload\u from\u file('f')文件“/Library/Python/2.7/site packages/google/cloud/storage/blob.py”,第891行,在upload\u from\u file client,file\u obj,file\u,content\u type,size,num\u retries)文件中“/Library/Python/2.7/site packages/google/cloud/storage/blob.py”,第815行,在“上传客户端、流、内容、类型、大小、重试次数”文件“/Library/Python/2.7/site packages/google/cloud/storage/blob.py”,第634行,在“上传多部分数据=stream.read()AttributeError:'str'对象没有属性'read',我猜您仍然在调用upload_from_file('t.json')。它应该是upload_from_file(f)。