Python request.post () возвращает ноль - PullRequest
0 голосов
/ 01 мая 2019

подскажите, пожалуйста, почему 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'
...