2016-10-24 9 views
0

urllibを使用してAPIを使用してディスクを注文しようとしていますが、応答としてBad requestを受け取りました。私は何が間違っているかも知れない。何か案は?SoftLayer API投稿時に間違った依頼

 url = "https://username:[email protected]/rest/v3/SoftLayer_Product_Order/placeOrder" 
     data = urllib.urlencode({ 
      "parameters": [{ 
       "virtualGuests": [{"id": idofvirtualguest}], 
       "prices": [{ 
        "id": 113031, 
        "categories": [{ 
         "categoryCode": "guest_disk1", 
         "complexType": "SoftLayer_Product_Item_Category" 
        }], 
        "complexType": "SoftLayer_Product_Item_Price" 
       }, 
        { 
         "id": 112707, 
         "categories": [{ 
          "categoryCode": "guest_disk2", 
          "complexType": "SoftLayer_Product_Item_Category" 
         }], 
         "complexType": "SoftLayer_Product_Item_Price" 
        } 
       ], 
       "properties": [ 
        {"name": "NOTE_GENERAL", "value": "adding disks"}, 
        {"name": "MAINTENANCE_WINDOW", "value": "now"} 
       ], 
       "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade" 
      }] 
     }) 

     response = urllib.urlopen(url, data) 

答えて

0

てみ使用する:代わりにurllib.urlencode

json.dumps注:それは一見する必要がありますので、あなたは、JSONをインポートする必要がありますこのように:

import urllib 
import json 

url = "https://username:[email protected]/rest/v3/SoftLayer_Product_Order/placeOrder" 
idofvirtualguest = 111122233 

data = json.dumps({ 
    "parameters": [{ 
     "virtualGuests": [{"id": idofvirtualguest}], 
     "prices": [{ 
      "id": 113031, 
      "categories": [{ 
       "categoryCode": "guest_disk1", 
       "complexType": "SoftLayer_Product_Item_Category" 
      }], 
      "complexType": "SoftLayer_Product_Item_Price" 
     }, 
      { 
       "id": 112707, 
       "categories": [{ 
        "categoryCode": "guest_disk2", 
        "complexType": "SoftLayer_Product_Item_Category" 
       }], 
       "complexType": "SoftLayer_Product_Item_Price" 
      } 
     ], 
     "properties": [ 
      {"name": "NOTE_GENERAL", "value": "adding disks"}, 
      {"name": "MAINTENANCE_WINDOW", "value": "now"} 
     ], 
     "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade" 
    }] 
}) 

response = urllib.urlopen(url, data) 
関連する問題