google云视觉API中如何去掉"no attribute enums error"

How to get rid of "no attribute enums error" in google cloud vision API

我目前正在使用 google cloud vision API 来翻译 pdf 文档,但我在代码中发现了一个错误。我目前正在使用语句

feature = vision_v1.types.Feature(
    type=vision_v1.enums.Feature.Type.DOCUMENT_TEXT_DETECTION)

但我收到错误消息:

"AttributeError: module 'google.cloud.vision_v1' has no attribute 'enums'"

我该如何解决这个问题?

要修复错误,您只需将代码行中的 enums 更改为 type,请参阅 Feature reference。还要将 type 更改为 type_,因为这是可接受的参数名称。

class google.cloud.vision_v1.types.Feature(mapping=None, *, ignore_unknown_fields=False, **kwargs) Bases: proto.message.Message

The type of Google Cloud Vision API detection to perform, and the maximum number of results to return for that type. Multiple Feature objects can be specified in the features list.

  • type_
    • The feature type.
  • Type: google.cloud.vision_v1.types.Feature.Type

请参阅下面的代码进行修复:

feature = vision_v1.types.Feature( type_=vision_v1.types.Feature.Type.DOCUMENT_TEXT_DETECTION)