【问题标题】:A Message class can only inherit from Message - PythonMessage 类只能从 Message 继承 - Python
【发布时间】:2020-05-04 21:54:13
【问题描述】:

我从 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 在服务器上运行代码。即使在重新启动服务后我也会收到此错误。请帮忙。

【问题讨论】:

  • 尝试将输出写成代码块,这样会更容易阅读,添加一些代码会很有用。
  • 就像 theFrok 所说,我们需要查看您的代码才能帮助您。
  • 这能回答你的问题吗? Strange error with Keras and Spyder

标签: python google-cloud-platform


【解决方案1】:

我找到了一种解决方法,我现在只在需要的地方调用谷歌云方法,而不是在应用初始化期间。

【讨论】:

    猜你喜欢
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 2021-06-10
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    相关资源
    最近更新 更多