Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python apiclient.discovery.build POST请求正文_Python_Google App Engine_Http Post_Google Api Client - Fatal编程技术网

Python apiclient.discovery.build POST请求正文

Python apiclient.discovery.build POST请求正文,python,google-app-engine,http-post,google-api-client,Python,Google App Engine,Http Post,Google Api Client,我的服务器googleappengineapi代码和客户端都使用python。我已经有很多客户端-服务器GET请求在工作,现在是发布请求的时候了,我被卡住了。我的相关客户代码: service = build("myAPI", "v1", http=http, discoveryServiceUrl=DISCOVERY_URL) service.updateUser(websafeKey=websafeKey).execute() 我不知道如何构建POST请求的主体。在那之后,我将一直试图弄清

我的服务器googleappengineapi代码和客户端都使用python。我已经有很多客户端-服务器GET请求在工作,现在是发布请求的时候了,我被卡住了。我的相关客户代码:

service = build("myAPI", "v1", http=http, discoveryServiceUrl=DISCOVERY_URL)
service.updateUser(websafeKey=websafeKey).execute()
我不知道如何构建POST请求的主体。在那之后,我将一直试图弄清楚如何告诉
服务
,以便它可以将请求发送到我的updateUser API

POST请求主体将需要包含一些字符串和几个列表,稍后可能还会包含一个python日期对象

我的
updateUser
API在API浏览器中运行良好-我可以整天成功地
updateUser

USER_POST_REQUEST = endpoints.ResourceContainer(
UserForm, websafeKey=messages.StringField(1),)
@endpoints.method(USER_POST_REQUEST, UserForm,
        path='useradmin/{websafeKey}',
        http_method='PUT', name='updateUser')
def updateUser(self, request):
    """Update user w/provided fields & return w/updated info."""
    return self._updateUserObject(request)

我自己想出来的。显然,您所需要做的就是定义一个字典,并将其作为服务方法调用中的
body
参数传递。以下是我所做的:

body = {'key1': user['info1'], 'key2': user['info2']}
service = build("myAPI", "v1", http=http, discoveryServiceUrl=DISCOVERY_URL)
service.updateFan(websafeFanKey=fan['websafeKey'], body=body).execute()
非常简单,真的,但我确实很难找到任何记录这一点的东西。希望其他人能从中受益