Sending data Curl/Json in Python

前端 未结 4 1654
遥遥无期
遥遥无期 2021-01-13 06:13

I`m trying to make those 2 requests in python:

Request 1:

 curl -X POST -H \"Content-Type: application/json\" -d \'{ \"auth_token\": \"auth1\", \"w         


        
4条回答
  •  情书的邮戳
    2021-01-13 06:41

    why not use urllib2?

    import urllib2
    import urllib
    
    vsphere_dict = dict(
        server_name="servername",
        api_version=apiVersion,
        guest_count=guestCount,
        guest_on=guestOnLen,
        guest_off=guestOffLen,
    )
    # create request object, set url and post data
    req = urllib2.Request(some_url, data=urllib.urlencode(vsphere_dict))
    # set header
    req.add_header('Content-Type', 'application/json')
    # send request
    response = urllib2.urlopen(req)
    

    UPD:

    sorry, by i not understand that is auth and widget. Maybe this is also POST data? HTTP Error 500 - can mean that server received not all POST parameters.

提交回复
热议问题