简体   繁体   English

对于openstack API,python不会解释JSON中的null值

[英]null value in JSON is not interpreted by python for openstack API

I am using OpenStack's REST API for programmatic implementation of start or stop server. 我正在使用OpenStack的REST API来实现启动或停止服务器的编程。

The link for API reference is http://api.openstack.org/api-ref.html#ext-os-server-start-stop This requires a dictionary in python as follows: API参考的链接是http://api.openstack.org/api-ref.html#ext-os-server-start-stop这需要python中的字典如下:

dict = {
     os-start:null
    } 

Then I am doing a json.dumps(dict) and making a post request to the openstack's public URL for nova module. 然后我正在做一个json.dumps(dict)并向openstack的nova模块的公共URL发出请求。

When I run this program ,error of unknown global name "null". 当我运行此程序时,未知全局名称“null”的错误。 Hence, its not working. 因此,它不起作用。

I want to know for this request of starting the server on OpenStack to work , what should I use as the value of field "os-start" in request JSON. 我想知道在OpenStack上启动服务器的这个请求是否有效,我应该在请求JSON中使用什么作为字段“os-start”的值。

Let me know if any additional information is needed. 如果需要任何其他信息,请与我们联系。

Thank you in advance. 先感谢您。

Python's None singleton is translated to a JSON null , and vice versa. Python的None单例被转换为JSON null ,反之亦然。 Use that instead: 使用它代替:

>>> import json
>>> json.dumps({'os-start': None})
'{"os-start": null}'
>>> json.loads('{"os-start": null}')
{u'os-start': None}

May be little off-topic, but as you are using openstack REST API, I also recommend to take a look at libcloud as well, it has openstack driver. 可能有点偏离主题,但是当你使用openstack REST API时,我也建议你看一下libcloud ,它有openstack驱动程序。

Libcloud not only provides a unified interface to the cloud, but also the abstract the access layer to openstack REST API Libcloud不仅提供了统一的云接口,还抽象了openstack REST API的访问层

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

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