大约十分之一的图像上传到谷歌云存储时,我会收到此错误。这段代码已经运行了几个月,在检查日志后我发现这个错误已经持续了几周。大多数图像都会上传,这就是为什么需要很长时间才能识别的原因。我在日志中看到的确切错误是: HTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries Excessed with URL: my_url?uploadType=multipart (由 ProxyError('Cannot connect to proxy.', ConnectionResetError(104, '连接被对等方重置'))) 有谁知道是什么原因导致的?
我的代码非常基本:
from google.cloud import storage
image = cv2.imread(imagePath)
jsonCreds = f"{Home}/Config/gcp_secret.json"
bucketName = os.environ.get('GCP_BUCKET')
storageClient = storage.Client.from_service_account_json(jsonCreds)
retval, gcpImageBuffer = cv2.imencode('.jpg',image)
gcpByteArray = gcpImageBuffer.tobytes()
bucket = storageClient.bucket(bucketName)
Create the full file path to save the image in the format YYYY/MM/DD/<AssetID>.jpg
assetID = IPAddress
imageFileName = imagePath.split('/')[-1]
components = imageFileName.split('_')
year = components[0]
month = components[1]
day = components[2]
hour = components[3]
minute= components[4]
second= components[5]
#change filename to assetid_timestamp
# uuidName=str( uuid.uuid4() )
gcpFilePath = "{}/{}/{}/{}_{}_{}_{}".format(year,month,day,assetID,hour,minute,second)
blob = bucket.blob(gcpFilePath)
blob.upload_from_string(gcpByteArray)
解决了吗?如果是,您能告诉我它是如何解决的吗?我在 cloudrun 中遇到以下错误
错误:“内部服务器错误” 消息:“('连接中止。',ConnectionResetError(104,'连接被对等方重置'))” 状态:500
代码很简单如下:
from google.cloud import storage
client = storage.Client.from_service_account_info(service_account_info) 桶 = client.bucket(my_bucket)