2

When I call Create API from the python console, It gives following exception.

Traceback (most recent call last):
File "<stdin>", line 3, in <module>
  File "C:\Python27\lib\v1pysdk\base_asset.py", line 44, in create
    return Class._v1_v1meta.create_asset(Class._v1_asset_type_name, newdata)
  File "C:\Python27\lib\v1pysdk\v1meta.py", line 128, in create_asset
    new_asset_xml = self.server.create_asset(asset_type_name,  update_doc)
  File "C:\Python27\lib\v1pysdk\client.py", line 202, in create_asset
    return self.get_xml(path, query=query, postdata=body)
  File "C:\Python27\lib\v1pysdk\client.py", line 159, in get_xml
    document = ElementTree.fromstring(body)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1281, in XML
    parser.feed(text)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1623, in feed
    self._raiseerror(v)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1487, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: reference to invalid character number: line 7575, column 75

I am running it with Python2.7 on windows. This is the API I am calling

from v1pysdk import V1Meta

v1 = V1Meta(
     address = 'www11.v1host.com',
     instance = '<InstName>',
     username = 'sbaid',
     password = 'XXXXXX'
     )

new_story = v1.Story.create(
    Name = "Temp",
    Scope = v1.Scope(321450)
    )

v1.Scope(321450) returns the correct project name, that implies that session with version1 is established correctly.

These are the only two mandatory parameters and I am able to create the story with these two parameters using Web interface.

I am also able to create the story using following REST request

URL - https://www11.v1host.com/InstName/rest-1.v1/Data/Story

<Asset href="/<InstName>/rest-1.v1/New/Story">
<Attribute name="Name" act="set">Temp</Attribute>
<Relation name="Scope" act="set">
<Asset href="/<InstName>/rest-1.v1/Data/Scope/321450" idref="Scope:321450" />
</Relation>
</Asset>
saurabh baid
  • 1,819
  • 1
  • 14
  • 26
  • Have you put in characters in xml such as `>` or `<` which will cause the parser to fail? Try opening the xml in internet explorer to see if it opens without error. If it does not, you might have to change the `<` and `>` to `lt;` and `gt;` respectively. – shahkalpesh May 12 '15 at 07:13
  • @shahkalpesh I am not passing any SML document explicityly, so any XML which is being generated is getting generated by the API itself. – saurabh baid May 12 '15 at 11:30

1 Answers1

1

There is an alternate way to specify the host address which is more reliable. Here's an example that you can try against the public VersionOne SDK testing instance:

from v1pysdk import V1Meta

with V1Meta (
     instance_url = 'https://www14.v1host.com/v1sdktesting',
     username = 'admin',
     password = 'admin'
     ) as v1:

    new_story = v1.Story.create(
        Name = "Temp Test for StackOverflow question",
        Scope = v1.Scope(0)
        )

    fetched_story = v1.Story.where(Number=new_story.Number).first()
    print fetched_story.Name
JoshGough
  • 964
  • 1
  • 8
  • 16
  • I have editited original question to include complete code. Is it possible to put some debug logs which can tell what REST request it is sending. I could create it successfully using following rest request – saurabh baid May 12 '15 at 06:43
  • @JoshGough: That can be a added as a comment instead of an answer. – shahkalpesh May 12 '15 at 07:13
  • It worked, Thanks. But what is the difference between the two methods? – saurabh baid May 14 '15 at 06:43
  • Well, I haven't dug into the code to see why the first one failed, but I would suspect that it might default to HTTP, but hosted versionone instances operate over HTTPS. But, when the client attempts to GET (to simply read an asset), it will follow the redirect to the HTTPS address that our servers automatically send, but I don't think that can be done in the case of an HTTP post. I'll look at the code and see if there is a protocol option that can be passed or added though if you prefer the other approach. – JoshGough May 14 '15 at 16:15
  • Well I dont have any preference over the method :). – saurabh baid May 15 '15 at 08:30