Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

generated python code doesn't work #179

Open
aerickson opened this issue Mar 11, 2019 · 1 comment
Open

generated python code doesn't work #179

aerickson opened this issue Mar 11, 2019 · 1 comment

Comments

@aerickson
Copy link

aerickson commented Mar 11, 2019

Versions I'm using:

coreapi                       2.3.3     
coreapi-cli                   1.0.9  
Python 2.7.16

API I'm trying to use: https://treeherder.mozilla.org/docs/#project-push-list
github repo for the project: https://github.com/mozilla/treeherder

Valid projects are 'try' and 'mozilla-central'. The following work fine.

coreapi get https://treeherder.mozilla.org/docs/
coreapi action project push list -p project=try
coreapi action project push list -p project=mozilla-central

curl "https://treeherder.mozilla.org/api/project/try/push/"
curl "https://treeherder.mozilla.org/api/project/mozilla-central/push/"

The python code (click 'Source Code' in lower left and select python) doesn't work.

test.py (nearly exactly from doc page, just setting project key)

#!/usr/bin/env python

import coreapi

# Initialize a client & load the schema document
client = coreapi.Client()
schema = client.get("https://treeherder.mozilla.org/docs/")

# Interact with the API endpoint
action = ["project", "push > list"]
params = {
    "project": "try",
    #"project": "mozilla-central", 
}
result = client.action(schema, action, params=params)
print(result)
➜  ~  ./test.py 
Traceback (most recent call last):
  File "./test.py", line 14, in <module>
    result = client.action(schema, action, params=params)
  File "/usr/local/lib/python2.7/site-packages/coreapi/client.py", line 163, in action
    link, link_ancestors = _lookup_link(document, keys)
  File "/usr/local/lib/python2.7/site-packages/coreapi/client.py", line 38, in _lookup_link
    raise exceptions.LinkLookupError(msg % (index_string, repr(key).strip('u')))
coreapi.exceptions.LinkLookupError: Index ['project']['push > list'] did not reference a link. Key 'push > list' was not found.
➜  ~

@aerickson
Copy link
Author

aerickson commented Mar 11, 2019

Hmm, the following change to the python code fixed it.

# from
action = ["project", "push > list"]
# to
action = ["project", "push", "list"]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant