小编Spa*_*ish的帖子

在 Python 中发送数据 Curl/Json

我正在尝试在 python 中发出这 2 个请求:

请求 1:

 curl -X POST -H "Content-Type: application/json" -d '{ "auth_token": "auth1", "widget":   "id1", "title": "Something1",  "text": "Some text", "moreinfo": "Subtitle" }'   serverip
Run Code Online (Sandbox Code Playgroud)

请求 2:

 vsphere_dict = {}
 vsphere_dict['server_name'] = "servername"
 vsphere_dict['api_version'] = apiVersion
 vsphere_dict['guest_count'] = guestCount
 vsphere_dict['guest_on']    = guestOnLen
 vsphere_dict['guest_off']   = guestOffLen

 #Convert output to Json to be sent
 data = json.dumps(vsphere_dict)

 curl -X POST -H "Content-Type: application/json" -d 'data' serverip
Run Code Online (Sandbox Code Playgroud)

它们似乎都不起作用。有什么办法可以用 Python 发送它们吗?

更新:

我无法处理的部分是通行证和小部件。我尝试了以下但没有成功:

import urllib2
import urllib

vsphere_dict = dict(
    server_name="servername", …
Run Code Online (Sandbox Code Playgroud)

python dashing

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

dashing ×1

python ×1