cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
171
Views
0
Helpful
2
Replies
Highlighted
Beginner

HTTPError: 405 Client Error: Method Not Allowed when pushing yang data

Hi

I'm trying to push some data using nornir framework, however when I receive error 404: method not allowed Error.

I'm using IOS-XE version 16.9.3  with csr1000v as my  test environment.

Python version: 3.7.3

 

There many policy-map configured on the device and what I'm trying to achieve is to change only a single policy-map config without changing other policy-maps.

 

He're is my code and It's respective host.yaml and groups.yaml file

#!/usr/bin/python3

import requests
from nornir import InitNornir
from nornir.plugins.tasks.apis import http_method
from nornir.plugins.functions.text import print_result

def manage_devices(task, policy, headers):
    BaseURL = f'https://{task.host.hostname}:{task.host.port}/restconf/'
    task.run(
        task=http_method,
        name='Update policy-map and class-map config via HTTP PUT',
        method='put',
        url=BaseURL + policy,
        auth=('XXXX', 'ZZZZZ'),
        headers=headers,
        verify=False,
        json=task.host['body']['Cisco-IOS-XE-native:policy']['Cisco-IOS-XE-policy:policy-map'][0],
    )
def main():

    requests.packages.urllib3.disable_warnings()
    policy_header = 'data/Cisco-IOS-XE-native:native/Cisco-IOS-XE-native:policy/Cisco-IOS-XE-policy:policy-map/'
    PutHeader = {
      'Content-Type': 'application/yang-data+json',
      'Accept': 'application/yang-data+json, application/yang-data.errors+json'
    }
    nornir = InitNornir()
    result = nornir.run(
        task=manage_devices,
        name='Configure devices via RESTCONF',
        policy=policy_header,
        headers=PutHeader,
    )
    print_result(result)

if __name__ == '__main__':
    main()

hosts file:

---
PE-R2:
  hostname: '172.17.105.6'
  port: '8802'
  groups:
    - 'csr1000v'
  data:
    body:             
      Cisco-IOS-XE-native:policy:
        Cisco-IOS-XE-policy:class-map:
        - name: CLASS_TEST
          prematch: match-all
          match:
            access-group:
              name:
              - ACL_COUNT_TEST
        Cisco-IOS-XE-policy:policy-map:
        - name: POLICY_TEST
          class:
          - name: CLASS_TEST  
... 

groups file

---
csr1000v:
 username: 'XXXX'
 password: 'ZZZZ'
 platform: 'ios'
 

It seems I'm not able to figure out the correct format to push configs to router.

I'm getting this Error message when running script:

requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://172.17.105.6:8802/restconf/data/Cisco-IOS-XE-native:native/Cisco-IOS-XE-native:policy/Cisco-IOS-XE-policy:policy-map/

Everyone's tags (1)
2 REPLIES 2
Cisco Employee

Re: HTTPError: 405 Client Error: Method Not Allowed when pushing yang data

This is known YDK issue. Unfortunately the IOS XE does not allow to have non-secure Restconf connection and YDK does not support secure HTTP connection. We will fix that issue as resources permit.

Beginner

Re: HTTPError: 405 Client Error: Method Not Allowed when pushing yang data

I'm not sure how is it related to that issue but the point is if I send without specifying nested keys like following snippet, configuration are pushed to router successfully:

json=task.host['body']

But when I try to push an specific part of the data, I receive '405 Client Error: Method Not Allowed for URL:'

json=task.host['body']['Cisco-IOS-XE-native:policy']['Cisco-IOS-XE-policy:policy-map'][0],
Content for Community-Ad
August's Community Spotlight Awards
This widget could not be displayed.