简体   繁体   English

Compute Engine 的 Python 客户端返回“未指定必填字段‘资源’”

[英]Python client for Compute Engine returns "Required field 'resource' not specified"

I'm trying to create a VM using the python client.我正在尝试使用 python 客户端创建一个 VM。 The call I'm making is我打的电话是

import googleapiclient.discovery

compute = googleapiclient.discovery.build('compute', 'v1')
compute.instances().insert(
    project='my-project',
    zone='us-central1-c',
    body=config).execute()

(config is a json string, available here ) (config 是一个 json 字符串,可在此处获得

and the response is响应是

<HttpError 400 when requesting https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/instances?alt=json
returned "Required field 'resource' not specified">

From this forum post and this stackexchange question , it appears the problem is with the REST API headers.this forum postthis stackexchange question来看,问题似乎出在REST API标头上。 However headers aren't exposed the python client, as far as I know.但是,据我所知,头文件没有暴露在 python 客户端中。

Is this a bug or is there something else I might be doing incorrectly?这是一个错误还是我可能做错了什么?

EDIT编辑

Following the error back to googleapiclient.http.HttpRequest , it looks like the HttpRequest object generated by build() has headers在错误返回googleapiclient.http.HttpRequest ,看起来build()生成的HttpRequest对象具有标头

{ 'accept': 'application/json',
  'accept-encoding': 'gzip, deflate',
  'content-length': '2299',
  'content-type': 'application/json',
  'user-agent': 'google-api-python-client/1.7.7 (gzip)' }

I tried adding 'resource': 'none' to the headers and received the same response.我尝试在标题中添加'resource': 'none'并收到相同的响应。

After looking at this for a while, I suspect the REST API is expecting a Compute Engine resource to be specified.看了一会儿之后,我怀疑 REST API 期望指定一个 Compute Engine 资源。 However, searching for the word "resource" on the official docs yields 546 results.但是,在官方文档上搜索“资源”一词会产生 546 个结果。

EDIT2编辑2

Created GitHub Issue .创建了GitHub 问题

使用请求正文(requestBody)”而不是资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM