Я получил эту ошибку, когда внедрил хранилище импорта google.cloud.
Traceback (most recent call last):
File "/mnt/apps/repo/oktested/oktested-backend/wsgi.py", line 1, in <module>
from ok_app import app as application
File "./ok_app/__init__.py", line 11, in <module>
from google.cloud import storage
File "/usr/lib/python3.6/site-packages/google/cloud/storage/__init__.py", line 38, in <module>
from google.cloud.storage.batch import Batch
File "/usr/lib/python3.6/site-packages/google/cloud/storage/batch.py", line 29, in <module>
from google.cloud import _helpers
File "/usr/lib/python3.6/site-packages/google/cloud/_helpers.py", line 33, in <module>
from google.protobuf import duration_pb2
File "/usr/lib64/python3.6/site-packages/google/protobuf/duration_pb2.py", line 69, in <module>
'__module__' : 'google.protobuf.duration_pb2'
TypeError: A Message class can only inherit from Message
unable to load app 1 (mountpoint='oktested') (callable not found or import error)
Код:
from google.cloud import storage
creds = storage.Client.from_service_account_json('s-creds.json')
def uploadProfilePic(id, image_name, image):
filename = id + '__' + str(uuid.uuid4()) + '__' + image_name
dest_dir = app.config['S3_DIR'] + app.config['PROFILE_PIC_PATH']
filepath = os.path.join(dest_dir, filename)
image_data = re.sub('^data:image/.+;base64,', '', image)
img_data = base64.b64decode(image_data)
try:
if 'jpeg' in filename:
image_type = "image/jpeg"
elif 'png' in filename:
image_type = "image/png"
elif 'jpg' in filename:
image_type = "image/jpg"
# s3.Bucket(app.config['S3_BUCKET_NAME']).put_object(Key=filepath, Body=img_data, ACL=app.config['S3_ACL'], ContentType ='image/jpeg', CacheControl=app.config['S3_CACHE_CONTROL'])
bucket = creds.bucket(app.config['GCP_BUCKET_NAME'])
blob = bucket.blob(filepath)
blob.upload_from_string(img_data, content_type=image_type)
app.logger.debug("User::uploadProfilePic::SuccessfullyUploaded::{}".format(filepath))
return filepath
except Exception as e:
app.logger.error("User::uploadProfilePic:: {}". format(e))
return ''
Я запускаю код на сервере с помощью uwsgi. Я получаю эту ошибку даже после перезапуска службы. Пожалуйста, помогите.