Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Python library unable to call API or Documentation incorrect #50

Closed
NathanHughes opened this issue Sep 8, 2020 · 5 comments
Closed
Assignees
Labels
api: dlp Issues related to the googleapis/python-dlp API. triage me I really want to be triaged.

Comments

@NathanHughes
Copy link

#23 ## Environment details

  • OS type and version: Both WIN10 and Databricks
  • Python version: 3.7
  • pip version: 20.2.2
  • google-cloud-dlp version: both 1.0.0 and 2.0.0

Steps to reproduce

  1. Run the example inspection code on either this site or from the Google documentation
  2. ?

Code example

# Import the client library
import google.cloud.dlp

# Instantiate a client.
dlp_client = google.cloud.dlp_v2.DlpServiceClient()

# The string to inspect
content = "Robert Frost"

# Construct the item to inspect.
item = {"value": content}

# The info types to search for in the content. Required.
info_types = [{"name": "FIRST_NAME"}, {"name": "LAST_NAME"}]

# The minimum likelihood to constitute a match. Optional.
min_likelihood = google.cloud.dlp_v2.Likelihood.LIKELIHOOD_UNSPECIFIED

# The maximum number of findings to report (0 = server maximum). Optional.
max_findings = 0

# Whether to include the matching string in the results. Optional.
include_quote = True

# Construct the configuration dictionary. Keys which are None may
# optionally be omitted entirely.
inspect_config = {
    "info_types": info_types,
    "min_likelihood": min_likelihood,
    "include_quote": include_quote,
    "limits": {"max_findings_per_request": max_findings},
}

# Convert the project id into a full resource id.
parent = f"projects/{project_id}"

# Call the API.
response = dlp_client.inspect_content(
    request={"parent": parent, "inspect_config": inspect_config, "item": item}
)

# Print out the results.
if response.result.findings:
    for finding in response.result.findings:
        try:
            print("Quote: {}".format(finding.quote))
        except AttributeError:
            pass
        print("Info type: {}".format(finding.info_type.name))
        # Convert likelihood value to string respresentation.
        likelihood = finding.likelihood.name
        print("Likelihood: {}".format(likelihood))
else:
    print("No findings.")

Stack trace

Version 1.0

TypeError: inspect_content() got an unexpected keyword argument 'request'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<command-52156> in <module>
      2 info_types = ['EMAIL_ADDRESS','PERSON_NAME','PHONE_NUMBER']
      3 
----> 4 inspect_string(project_id,working_text, info_types )

<command-53225> in inspect_string(project, content_string, info_types, custom_dictionaries, custom_regexes, min_likelihood, max_findings, include_quote)
     75     # Call the API.
     76     response = dlp.inspect_content(
---> 77         request={"parent": parent, "inspect_config": inspect_config, "item": item}
     78     )
     79 

TypeError: inspect_content() got an unexpected keyword argument 'request'

Version 2.0

AttributeError                            Traceback (most recent call last)
<ipython-input-2-780d6f9179a9> in <module>
----> 1 from google.cloud import dlp_v2
      2 from google.oauth2 import service_account

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\__init__.py in <module>
     16 #
     17 
---> 18 from .services.dlp_service import DlpServiceClient
     19 from .types.dlp import Action
     20 from .types.dlp import ActivateJobTriggerRequest

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\services\dlp_service\__init__.py in <module>
     16 #
     17 
---> 18 from .client import DlpServiceClient
     19 from .async_client import DlpServiceAsyncClient
     20 

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\services\dlp_service\client.py in <module>
     31 from google.oauth2 import service_account  # type: ignore
     32 
---> 33 from google.cloud.dlp_v2.services.dlp_service import pagers
     34 from google.cloud.dlp_v2.types import dlp
     35 from google.protobuf import field_mask_pb2 as field_mask  # type: ignore

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\services\dlp_service\pagers.py in <module>
     18 from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple
     19 
---> 20 from google.cloud.dlp_v2.types import dlp
     21 
     22 

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\types\__init__.py in <module>
     40     TableOptions,
     41 )
---> 42 from .dlp import (
     43     ExcludeInfoTypes,
     44     ExclusionRule,

~\AppData\Roaming\Python\Python37\site-packages\google\cloud\dlp_v2\types\dlp.py in <module>
   2306 
   2307 
-> 2308 class Value(proto.Message):
   2309     r"""Set of primitive values supported by the system. Note that for the
   2310     purposes of inspection or transformation, the number of bytes

~\AppData\Roaming\Python\Python37\site-packages\proto\message.py in __new__(mcls, name, bases, attrs)
    137                 # that index to the field's descriptor.
    138                 oneofs.setdefault(field.oneof, len(oneofs))
--> 139                 field.descriptor.oneof_index = oneofs[field.oneof]
    140 
    141             # If this field references a message, it may be from another

~\AppData\Roaming\Python\Python37\site-packages\proto\fields.py in descriptor(self)
     94                 type_name = self.enum
     95             elif self.enum:
---> 96                 type_name = self.enum._meta.full_name
     97 
     98             # Set the descriptor.

c:\users\nhughes\appdata\roaming\python\python37\site-packages\google\protobuf\internal\enum_type_wrapper.py in __getattr__(self, name)
    113       pass  # fall out to break exception chaining
    114     raise AttributeError('Enum {} has no value defined for name {!r}'.format(
--> 115         self._enum_type.name, name))

AttributeError: Enum DayOfWeek has no value defined for name '_meta'

Furthermore this code was working correctly last week

@product-auto-label product-auto-label bot added the api: dlp Issues related to the googleapis/python-dlp API. label Sep 8, 2020
@NathanHughes
Copy link
Author

As an addendum, we just got the 1.0.0 version to work in a fresh environment, the rollback must have not reverted all files

@busunkim96
Copy link
Contributor

busunkim96 commented Sep 8, 2020

@NathanHughes Would you mind checking which version of proto-plus is installed? If it is 1.9.0, could you try reverting to 1.8.1 (for the 2.0.0 code)?

Root cause is likely googleapis/proto-plus-python#115. I thought I had pushed a release to revert this last week but it looks like it didn't go through.

@NathanHughes
Copy link
Author

@busunkim96 Hi that seems to have fixed it, thank you very much

@busunkim96
Copy link
Contributor

@NathanHughes Thanks for checking that! I'll work on getting a new release of proto-plus out.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Sep 9, 2020
@busunkim96
Copy link
Contributor

proto-plus==1.9.1 reverted the problematic changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: dlp Issues related to the googleapis/python-dlp API. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants