<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic YDK returns a IndexError: basic_string::at when converting from a YML in Tools</title>
    <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4584779#M1046</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;YDK is returning &lt;STRONG&gt;IndexError: basic_string::at&lt;/STRONG&gt; error when converting a file from YML to XML which was originally converted successfully from XML -&amp;gt; YML.&lt;/P&gt;&lt;P&gt;Error returned is the following&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):
  File "convert.py", line 166, in &amp;lt;module&amp;gt;
    print(yang_yaml_to_xml(ARGS['yaml_file']))
  File "convert.py", line 134, in yang_yaml_to_xml
    decoded_json_yang = CODEC.decode(JSON_PROVIDER, config_json_yang)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
    return func(self, provider, entity, *args, **kwargs)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 140, in decode
    return self._decode(provider, payload_holder, subtree)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 174, in _decode
    root_data_node = codec_service.decode(root_schema, payload, provider.encoding)
IndexError: basic_string::at&lt;/PRE&gt;&lt;P&gt;Offending code in YAML is, specifically the empty choice-value string: choice-value: ''. The element was generated by YDK when converting from XML to YML&lt;/P&gt;&lt;PRE&gt;  junos-conf-policy-options:policy-options:
    policy-statement:
    - name: TEST
      term:
      - from:
          protocol:
          - ospf
          route-filter:
          - address: 1.1.1.0/24
            choice-ident: orlonger
            choice-value: ''
        name: OSPF
        then:
          accept:
          - null&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;XML code used for the conversion to YML - omitted the full policy. Issue can be easily reproducible on my system when &amp;lt;choice-value/&amp;gt; has no value which is the case for route filters such as exact, orlonger.&lt;/P&gt;&lt;PRE&gt;        &amp;lt;name&amp;gt;OSPF-ACCEPT&amp;lt;/name&amp;gt;
        &amp;lt;from&amp;gt;
          &amp;lt;protocol&amp;gt;ospf&amp;lt;/protocol&amp;gt;
          &amp;lt;route-filter&amp;gt;
            &amp;lt;address&amp;gt;1.1.1.0/24&amp;lt;/address&amp;gt;
            &amp;lt;choice-ident&amp;gt;orlonger&amp;lt;/choice-ident&amp;gt;
            &amp;lt;choice-value/&amp;gt;
          &amp;lt;/route-filter&amp;gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 06:40:56 GMT</pubDate>
    <dc:creator>ldacol</dc:creator>
    <dc:date>2022-04-04T06:40:56Z</dc:date>
    <item>
      <title>YDK returns a IndexError: basic_string::at when converting from a YML</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4584779#M1046</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;YDK is returning &lt;STRONG&gt;IndexError: basic_string::at&lt;/STRONG&gt; error when converting a file from YML to XML which was originally converted successfully from XML -&amp;gt; YML.&lt;/P&gt;&lt;P&gt;Error returned is the following&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):
  File "convert.py", line 166, in &amp;lt;module&amp;gt;
    print(yang_yaml_to_xml(ARGS['yaml_file']))
  File "convert.py", line 134, in yang_yaml_to_xml
    decoded_json_yang = CODEC.decode(JSON_PROVIDER, config_json_yang)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
    return func(self, provider, entity, *args, **kwargs)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 140, in decode
    return self._decode(provider, payload_holder, subtree)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 174, in _decode
    root_data_node = codec_service.decode(root_schema, payload, provider.encoding)
IndexError: basic_string::at&lt;/PRE&gt;&lt;P&gt;Offending code in YAML is, specifically the empty choice-value string: choice-value: ''. The element was generated by YDK when converting from XML to YML&lt;/P&gt;&lt;PRE&gt;  junos-conf-policy-options:policy-options:
    policy-statement:
    - name: TEST
      term:
      - from:
          protocol:
          - ospf
          route-filter:
          - address: 1.1.1.0/24
            choice-ident: orlonger
            choice-value: ''
        name: OSPF
        then:
          accept:
          - null&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;XML code used for the conversion to YML - omitted the full policy. Issue can be easily reproducible on my system when &amp;lt;choice-value/&amp;gt; has no value which is the case for route filters such as exact, orlonger.&lt;/P&gt;&lt;PRE&gt;        &amp;lt;name&amp;gt;OSPF-ACCEPT&amp;lt;/name&amp;gt;
        &amp;lt;from&amp;gt;
          &amp;lt;protocol&amp;gt;ospf&amp;lt;/protocol&amp;gt;
          &amp;lt;route-filter&amp;gt;
            &amp;lt;address&amp;gt;1.1.1.0/24&amp;lt;/address&amp;gt;
            &amp;lt;choice-ident&amp;gt;orlonger&amp;lt;/choice-ident&amp;gt;
            &amp;lt;choice-value/&amp;gt;
          &amp;lt;/route-filter&amp;gt;&lt;/PRE&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 06:40:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4584779#M1046</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-04-04T06:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: YDK returns a IndexError: basic_string::at when converting from a</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4585394#M1047</link>
      <description>&lt;P&gt;Hi Luca&lt;/P&gt;&lt;P&gt;The YDK does not offer service to convert from/to YAML. It is completely on the user side. If you see YDK codec issue in conversion of YANG model compliant XML or JSON payload, then we can have the discussion.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Yan&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 15:52:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4585394#M1047</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-04-04T15:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: YDK returns a IndexError: basic_string::at when converting from a</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4585730#M1048</link>
      <description>&lt;P&gt;Hi Yan,&lt;/P&gt;&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;I am aware YDK does not convert from/to YAML which I am doing via json.dumps methods. I omitted the explanation for the sake of space and assumed the json method would return the correct payload, apologies for that. In any case, the same error is reproducible via JSON payload which was converted by YDK from XML code downloaded from a Juniper device. Here the json payload is converted from XML (I omit the XML payload for the sake of space)&lt;/P&gt;&lt;PRE&gt;{
  "junos-conf-root:configuration": {
    "junos-conf-policy-options:policy-options": {
      "policy-statement": [
        {
          "name": "IPV4",
          "term": [
            {
              "name": "OSPF-ACCEPT",
              "from": {
                "protocol": [
                  "ospf"
                ],
                "route-filter": [
                  {
                    "address": "1.1.1.0/24",
                    "choice-ident": "orlonger",
                    "choice-value": ""
                  }
                ]
              },
              "then": {
                "accept": [null]
              }
            }
          ]
        }
      ]
    }
  }
}&lt;/PRE&gt;&lt;P&gt;The error returned is the same as in my previous post&lt;/P&gt;&lt;PRE&gt;{"junos-conf-root:configuration": {"junos-conf-policy-options:policy-options": {"policy-statement": [{"name": "IPV4", "term": [{"name": "OSPF-ACCEPT", "from": {"protocol": ["ospf"], "route-filter": [{"address": "1.1.1.0/24", "choice-ident": "orlonger", "choice-value": ""}]}, "then": {"accept": [null]}}]}]}}}
Traceback (most recent call last):
  File "convert1.py", line 249, in &amp;lt;module&amp;gt;
    print(yang_yaml_to_xml(ARGS['yaml_file']))
  File "convert1.py", line 218, in yang_yaml_to_xml
    decoded_json_yang = CODEC.decode(JSON_PROVIDER, config_json_yang)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/errors/error_handler.py", line 112, in helper
    return func(self, provider, entity, *args, **kwargs)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 140, in decode
    return self._decode(provider, payload_holder, subtree)
  File "/opt/neteng/lib/python3.6/site-packages/ydk/services/codec_service.py", line 174, in _decode
    root_data_node = codec_service.decode(root_schema, payload, provider.encoding)
IndexError: basic_string::at&lt;/PRE&gt;&lt;P&gt;Any string on choice-value &amp;lt;&amp;gt; from "" (which was correctly returned by the XML -&amp;gt; JSON conversion) would return a successful conversion to XML&lt;/P&gt;&lt;PRE&gt;{"junos-conf-root:configuration": {"junos-conf-policy-options:policy-options": {"policy-statement": [{"name": "IPV4", "term": [{"name": "OSPF-ACCEPT", "from": {"protocol": ["ospf"], "route-filter": [{"address": "1.1.1.0/24", "choice-ident": "orlonger", "choice-value": "orlonger"}]}, "then": {"accept": [null]}}]}]}}}
&amp;lt;configuration xmlns="http://yang.juniper.net/junos/conf/root"&amp;gt;
  &amp;lt;policy-options xmlns="http://yang.juniper.net/junos/conf/policy-options"&amp;gt;
    &amp;lt;policy-statement&amp;gt;
      &amp;lt;name&amp;gt;IPV4&amp;lt;/name&amp;gt;
      &amp;lt;term&amp;gt;
        &amp;lt;name&amp;gt;OSPF-ACCEPT&amp;lt;/name&amp;gt;
        &amp;lt;from&amp;gt;
          &amp;lt;protocol&amp;gt;ospf&amp;lt;/protocol&amp;gt;
          &amp;lt;route-filter&amp;gt;
            &amp;lt;address&amp;gt;1.1.1.0/24&amp;lt;/address&amp;gt;
            &amp;lt;choice-ident&amp;gt;orlonger&amp;lt;/choice-ident&amp;gt;
            &amp;lt;choice-value&amp;gt;orlonger&amp;lt;/choice-value&amp;gt;
          &amp;lt;/route-filter&amp;gt;
        &amp;lt;/from&amp;gt;
        &amp;lt;then&amp;gt;
          &amp;lt;accept/&amp;gt;
        &amp;lt;/then&amp;gt;
      &amp;lt;/term&amp;gt;
    &amp;lt;/policy-statement&amp;gt;
  &amp;lt;/policy-options&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/PRE&gt;&lt;P&gt;The issue in the conversion JSON&amp;nbsp; -&amp;gt; XML seems to be the empty string for choice-value, which for the above payload would be a legitimate value.&lt;BR /&gt;Code for the conversion&lt;/P&gt;&lt;PRE&gt;def yang_yaml_to_xml(json_file):
    config_json_yang = json.dumps(json.load(open(json_file)))
    print (config_json_yang)
    decoded_json_yang = CODEC.decode(JSON_PROVIDER, config_json_yang)
    yang_xml = CODEC.encode(XML_PROVIDER, decoded_json_yang)
    return yang_xml&lt;/PRE&gt;&lt;P&gt;Thank you in advance for the comment and for always providing quick replies,&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 01:59:23 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4585730#M1048</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-04-05T01:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: YDK returns a IndexError: basic_string::at when converting from a</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4586690#M1049</link>
      <description>&lt;P&gt;Hi Luca&lt;/P&gt;&lt;P&gt;I reproduced the issue in test environment. It is a bug! Could you please open new issue &lt;A href="https://github.com/CiscoDevNet/ydk-gen/issues" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Yan&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:53:59 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4586690#M1049</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-04-05T16:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: YDK returns a IndexError: basic_string::at when converting from a</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4586881#M1050</link>
      <description>&lt;P&gt;HI Yan,&lt;/P&gt;&lt;P&gt;Done: &lt;A href="https://github.com/CiscoDevNet/ydk-gen/issues/1061" target="_blank"&gt;https://github.com/CiscoDevNet/ydk-gen/issues/1061&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Luca&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 02:53:17 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4586881#M1050</guid>
      <dc:creator>ldacol</dc:creator>
      <dc:date>2022-04-06T02:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: YDK returns a IndexError: basic_string::at when converting from a</title>
      <link>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4587412#M1051</link>
      <description>&lt;P&gt;Hi Luca&lt;/P&gt;&lt;P&gt;I have resolved the issue. The fix will be available in the next patch release (0.8.6.3). If this is critical for your project, you can get the fix in my &lt;A href="https://github.com/ygorelik/ydk-gen" target="_self"&gt;fork&lt;/A&gt; master branch.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Yan&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 15:36:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/ydk-returns-a-indexerror-basic-string-at-when-converting-from-a/m-p/4587412#M1051</guid>
      <dc:creator>ygorelik</dc:creator>
      <dc:date>2022-04-06T15:36:31Z</dc:date>
    </item>
  </channel>
</rss>

