Ошибка импорта задач Google Cloud: невозможно импортировать имя "resource_pb2"

Попытка использовать предоставленный Google образец кода Python для добавления задачи в очередь Google Cloud Tasks. Документы от Google находятся здесь: https://cloud.google.com/tasks/docs/creating-appengine-tasks

Когда я пытаюсь выполнить конечную точку, я получаю следующую ошибку:

ImportError: невозможно импортировать имя "resource_pb2"

Кто-нибудь видел подобную проблему и знает, как ее решить?

Спасибо заранее за ваше время :)

-Натан

Я попытался добавить google-cloud-tasks, google-api, google-cloud в свой файл requirements.txt и запустить pip install google-cloud-tasks в моей виртуальной среде. Я также пробовал использовать этот код:

из google.cloud import tasks_v2beta3

Результаты были такими же

Это пример кода, предоставленный Google. Я отправил им записку, чтобы сообщить, что пример кода не работает.

from google.cloud import tasks_v2
from google.protobuf import timestamp_pb2

# Create a client.
client = tasks_v2.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# queue = 'my-appengine-queue'
# location = 'us-central1'
# payload = 'hello'

# Construct the fully qualified queue name.
parent = client.queue_path(project, location, queue)

# Construct the request body.
task = {
        'app_engine_http_request': {  # Specify the type of request.
            'http_method': 'POST',
            'relative_uri': '/example_task_handler'
        }
}
if payload is not None:
    # The API expects a payload of type bytes.
    converted_payload = payload.encode()

    # Add the payload to the request.
    task['app_engine_http_request']['body'] = converted_payload

if in_seconds is not None:
    # Convert "seconds from now" into an rfc3339 datetime string.
    d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds)

    # Create Timestamp protobuf.
    timestamp = timestamp_pb2.Timestamp()
    timestamp.FromDatetime(d)

    # Add the timestamp to the tasks.
    task['schedule_time'] = timestamp

# Use the client to build and send the task.
response = client.create_task(parent, task)

print('Created task {}'.format(response.name))
return response

Я ожидал, что код добавит задачу в очередь облачных задач, вместо этого я получил эту трассировку стека:

Traceback (most recent call last)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/athena_nsunderman/posttest-get/main.py", line 134, in TestQueueInsert
from google.cloud import tasks_v2
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/google/cloud/tasks_v2/__init__.py", line 19, in <module>
from google.cloud.tasks_v2 import types
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/google/cloud/tasks_v2/types.py", line 22, in <module>
from google.cloud.tasks_v2.proto import cloudtasks_pb2
File "/home/athena_nsunderman/virtualenv/recharge/lib/python3.5/site-packages/google/cloud/tasks_v2/proto/cloudtasks_pb2.py", line 18, in <module>
from google.api import resource_pb2 as google_dot_api_dot_resource__pb2
ImportError: cannot import name 'resource_pb2'
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

person Nathan-NWCC    schedule 29.05.2019    source источник


Ответы (1)


Это сработало для меня:

pip install -U googleapis-common-protos==1.5.10

person Sravani Baswaraj    schedule 14.06.2019