Python request.post()返回null

时间:2019-05-01 13:20:09

标签: python-3.x post basic-authentication

能否请您告诉我为什么python.requests.post()返回null

我已经尝试过

r=requests.request("POST",url, json=data, headers=headers)

r=requests.post(url, data=json.dumps(data), headers=headers)
import requests
import xlrd
import json

api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
headers = {'Authorization': 'Basic %s' %api_key,'content-type': 'application/json'}
url = 'https://dev.networks.in.telstra.com.au/change/api/create'
file = "final_data.xlsx"
wb = xlrd.open_workbook(file)
ws = wb.sheet_by_name('Sheet1')
for i in range(ws.nrows):    
    node=(ws.cell_value(i,0))
    starttime=(ws.cell_value(i,1))
    endtime=(ws.cell_value(i,2))

    data = {"context": "External Power Suppliers",
            "activity_type": "Planned Power Works",
            "activity": "Power Interruptions",
            "title": "Test change for Power Interruption",
            "description": "Planned Power outage notification from external providers: NAME of the provider",
            "start_time" : starttime,
            "end_time": endtime,
            "risk_level": "LOW",
            "impact_level": "LOW",
            "resources" : [           
                 { "name":node, "resource_type": "NETWORK-ELEMENT"}],
            "contacts": [
                { "userid":"d806851", "relationship":"CHANGE-IMPLEMENTER"}],
            "locations": [
                { "node_code":node, "location":"CLAY - CLAYTON TRANSMISSION (CLAYTON EXCHANGE)"}]
            }
    r=requests.request("POST",url, json=data, headers=headers)
    response = r.status_code
    print(response,r.json(),r.text)
    print(r.request.url)
    print(r.request.body)

我得到的状态码为200,但响应为{} !!!

我期待一个json

200 {} {}

https://dev.networks.in.telstra.com.au/change/api/create
b'{"context": "External Power Suppliers", "activity_type": "Planned Power Works", "activity": "Power Interruptions", "title": "Test change for Power Interruption", "description": "Planned Power outage notification from external providers: NAME of the provider", "start_time": "2019-05-14T09:30:00+00:00", "end_time": "2019-05-14T15:00:00+00:00", "risk_level": "LOW", "impact_level": "LOW", "resources": [{"name": "TBRM", "resource_type": "NETWORK-ELEMENT"}], "contacts": [{"userid": "d806851", "relationship": "CHANGE-IMPLEMENTER"}], "locations": [{"node_code": "TBRM", "location": "CLAY - CLAYTON TRANSMISSION (CLAYTON EXCHANGE)"}]}'
b'{}\n'

200 {} {}

https://dev.networks.in.telstra.com.au/change/api/create
b'{"context": "External Power Suppliers", "activity_type": "Planned Power Works", "activity": "Power Interruptions", "title": "Test change for Power Interruption", "description": "Planned Power outage notification from external providers: NAME of the provider", "start_time": "2019-04-09T09:00:00+00:00", "end_time": "2019-04-09T15:00:00+00:00", "risk_level": "LOW", "impact_level": "LOW", "resources": [{"name": "BJFY", "resource_type": "NETWORK-ELEMENT"}], "contacts": [{"userid": "d806851", "relationship": "CHANGE-IMPLEMENTER"}], "locations": [{"node_code": "BJFY", "location": "CLAY - CLAYTON TRANSMISSION (CLAYTON EXCHANGE)"}]}'
b'{}\n'

0 个答案:

没有答案