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

API returns "400 Request contains an invalid argument." #161

Closed
mitsuo0114 opened this issue Jun 11, 2021 · 8 comments
Closed

API returns "400 Request contains an invalid argument." #161

mitsuo0114 opened this issue Jun 11, 2021 · 8 comments
Assignees
Labels
api: securitycenter Issues related to the googleapis/python-securitycenter API. type: question Request for information or clarification. Not an issue.

Comments

@mitsuo0114
Copy link

Hi, I'm not sure this is bug but please allow me to file this issue.

Environment details

  • OS type and version: Windows 10
  • Python version: python --version 3.8.6
  • pip version: pip --version 21.1.2
  • google-cloud-securitycenter version: pip show google-cloud-securitycenter

pip show google-cloud-securitycenter
Name: google-cloud-securitycenter
Version: 1.3.0
Summary: Cloud Security Command Center API client library
Home-page: https://github.com/googleapis/python-securitycenter
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Location: c:\w\workspaces\python\gcptest\venv\lib\site-packages
Requires: packaging, google-api-core, proto-plus, grpc-google-iam-v1
Required-by:

Steps to reproduce

  1. just Run my Code example

Code example

This is almost same as given code on manual.
https://cloud.google.com/security-command-center/docs/how-to-api-list-assets?hl=ja

# example
from google.cloud.securitycenter import SecurityCenterClient

< configure my credential args and organization_id>

client = SecurityCenterClient.from_service_account_info(info=credential_args)
org_name = "organizations/{org_id}".format(org_id=organization_id)
asset_iterator = client.list_assets(request={"parent": org_name})
for i, asset_result in enumerate(asset_iterator):
    print(i, asset_result)

Below codes are works well. I've used this to make sure my credentials are valid,

from google.oauth2 import service_account
credential = service_account.Credentials.from_service_account_info(info=credential_args)
alternate_client = resource_manager.Client(credentials=credential)
project_iterator = alternate_client.list_projects()
for i, project in enumerate(project_iterator):
    print(i, project)

When I input wrong organization_id, I got another error. so I've assumed my organization_id is correct.

google.api_core.exceptions.InvalidArgument: 400 Fail to resolve resource 'organizations/Dummy'

Stack trace

Traceback (most recent call last):
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 67, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.INVALID_ARGUMENT
	details = "Request contains an invalid argument."
	debug_error_string = "{"created":"@1623379341.990000000","description":"Error received from peer ipv4:172.217.31.138:443","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/w/workspaces/python/gcptest/main.py", line 29, in <module>
    asset_iterator = client.list_assets(request={"parent": org_name})
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\cloud\securitycenter_v1\services\security_center\client.py", line 1401, in list_assets
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\retry.py", line 285, in retry_wrapped_func
    return retry_target(
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\retry.py", line 188, in retry_target
    return target()
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 69, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

@product-auto-label product-auto-label bot added the api: securitycenter Issues related to the googleapis/python-securitycenter API. label Jun 11, 2021
@busunkim96
Copy link
Contributor

Hi,

I'm not sure what's happening from the error message. It's possible there's additional information hidden in the error details (we're working on surfacing that information in googleapis/python-api-core#99).

Could you pip install grpcio-status and try doing this to unpack the error?

from google.rpc import error_details_pb2
from grpc_status import rpc_status
from google.cloud.securitycenter import SecurityCenterClient

< configure my credential args and organization_id>

client = SecurityCenterClient.from_service_account_info(info=credential_args)
org_name = "organizations/{org_id}".format(org_id=organization_id)

try:
    asset_iterator = client.list_assets(request={"parent": org_name})
except GoogleAPICallError as rpc_error:
   status = rpc_status.from_call(rpc_error.errors[0])
   for detail in status.details:
       if detail.Is(error_details_pb2.BadRequest.DESCRIPTOR):
           info = error_details_pb2.BadRequest()
           detail.Unpack(info)
           print(info)

@busunkim96 busunkim96 added the type: question Request for information or clarification. Not an issue. label Jun 11, 2021
@busunkim96 busunkim96 self-assigned this Jun 11, 2021
@mitsuo0114
Copy link
Author

mitsuo0114 commented Jun 13, 2021

Hi, Thank you for your advice!
I've installed grpcio-status and rerun but the status seems to be None.
Could you advice me if I should install different version of grpcio-status?

>pip show grpcio-status
Name: grpcio-status
Version: 1.38.0
Summary: Status proto mapping for gRPC
Home-page: https://grpc.io
Author: The gRPC Authors
Author-email: [email protected]
License: Apache License 2.0
Location: c:\w\workspaces\python\gcptest\venv\lib\site-packages
Requires: protobuf, googleapis-common-protos, grpcio
Required-by:
client = SecurityCenterClient.from_service_account_info(info=credential_args)
org_name = "organizations/{org_id}".format(org_id=organization_id)
try:
    asset_iterator = client.list_assets(request={"parent": org_name})
except GoogleAPICallError as rpc_error:
   status = rpc_status.from_call(rpc_error.errors[0])
   for detail in status.details:
       if detail.Is(error_details_pb2.BadRequest.DESCRIPTOR):
           info = error_details_pb2.BadRequest()
           detail.Unpack(info)
           print(info)

Traceback (most recent call last):
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 67, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.INVALID_ARGUMENT
	details = "Request contains an invalid argument."
	debug_error_string = "{"created":"@1623628042.047000000","description":"Error received from peer ipv4:142.250.196.106:443","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/w/workspaces/python/gcptest/main2.py", line 32, in <module>
    asset_iterator = client.list_assets(request={"parent": org_name})
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\cloud\securitycenter_v1\services\security_center\client.py", line 1401, in list_assets
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\retry.py", line 285, in retry_wrapped_func
    return retry_target(
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\retry.py", line 188, in retry_target
    return target()
  File "C:\w\workspaces\python\gcptest\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 69, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/w/workspaces/python/gcptest/main2.py", line 35, in <module>
    for detail in status.details:
AttributeError: 'NoneType' object has no attribute 'details'

```

@busunkim96
Copy link
Contributor

Ah it looks like there aren't any additional details to unpack. Thank you for trying that!

One more question - could you try listing assets on a single project and see if that call succeeds? client.list_assets(request={"parent": "projects/my-project-id"})

In the meantime I've filed an issue on the API team's issue tracker: https://issuetracker.google.com/issues/191040080.

@mitsuo0114
Copy link
Author

Really appreciate your support!
I've tried the single project list_assets call with enumerating available projects but it return same error code.

Source :

credential = service_account.Credentials.from_service_account_info(info=credential_args)
securitycenter_client = SecurityCenterClient.from_service_account_info(info=credential_args)
resource_client = resource_manager.Client(credentials=credential)

project_iterator = resource_client.list_projects()
for i, project in enumerate(project_iterator):
    try:
        print(f"Calling list_asset for {project.full_name}")
        asset_iterator = securitycenter_client.list_assets(request={"parent": project.full_name})
    except GoogleAPICallError as rpc_error:
        print(rpc_error)

Output
(Please allow me to mask actual project key in output)

(omit)
.
.
Calling list_asset for projects/xxxxxx-cert-group
400 Request contains an invalid argument.
.
.
(omit)

Please let me know if I can give more info for the investigation.

@mitsuo0114
Copy link
Author

Hi, I'm not sure why but today I confirmed my above code is working correctly.
I believe something was changed in Server end.

Thank you for your support and let me close this ticket.
Please let me know If I need to do something for you!

@marcraft2
Copy link

marcraft2 commented Oct 23, 2022

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.9/dist-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.INVALID_ARGUMENT
	details = "Request contains an invalid argument."
	debug_error_string = "UNKNOWN:Error received from peer ipv6:%5B2a00:1450:4007:818::200a%5D:443 {created_time:"2022-10-23T01:20:38.331598609+02:00", grpc_status:3, grpc_message:"Request contains an invalid argument."}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/nas-01/qrbot/QRBot/py/qrbot", line 86, in <module>
    create_video(con, language, 5)
  File "/nas-01/qrbot/QRBot/py/qrbot", line 19, in create_video
    video.maker(con, language, q)
  File "/nas-01/qrbot/QRBot/py/services/video.py", line 200, in maker
    tmp['duration'] = text_to_wav(rep_phrase, filename, voice)
  File "/nas-01/qrbot/QRBot/py/services/audio.py", line 19, in text_to_wav
    response = client.synthesize_speech(
  File "/usr/local/lib/python3.9/dist-packages/google/cloud/texttospeech_v1/services/text_to_speech/client.py", line 634, in synthesize_speech
    response = rpc(
  File "/usr/local/lib/python3.9/dist-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

Edit (Solution) :

text = text.replace("^s", " ").replace("^t", "    ")

@busunkim96
Copy link
Contributor

@marcdubois71450 Please open a new issue on the text-to-speech repository: https://github.com/googleapis/python-texttospeech with the information you provided and someone will get back to you. It's best to open new issues rather than commenting one closed issues as repository owners have better visibility into new issues.

Thank you!

@marcraft2
Copy link

marcraft2 commented Oct 24, 2022

In fact I just fixed with this:

text = text.replace("^s", " ").replace("^t", "    ")

This does not require issues, the error was in my code.

Problème char :

'�' => U+0093
'�' => U+0094

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: securitycenter Issues related to the googleapis/python-securitycenter API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants