1
votes

i met a problem by using requests.get() on kubernetes api

url = 'http://10.69.117.136:8080/api/v1/namespaces/"default"/pods/tas-core/'
json = requests.get(url)
print json.content

error code 404 will be returned as: {"kind": "Status","apiVersion": "v1","metadata": {},"status": "Failure","message": "pods \"tas-core\" not found","reason": "NotFound","details": {"name": "tas-core","kind": "pods"},"code": 404}

but if i use GET/curl, the response could be returned successfully:

curl http://10.69.117.136:8080/api/v1/namespaces/"default"/pods/tas-core/

{"kind": "Pod","apiVersion": "v1","metadata": {"name": "tas-core","namespace":"default","selfLink": "/api/v1/namespaces/default/pods/tas-core","uid": "a264ce8e-a956-11e5-8293-0050569761f2","resourceVersion": "158546","creationTimestamp": "2015-12-23T09:22:06Z","labels": {"app": "tas-core"},"annotations": {"ctrl": "dynamic","oam": "dynamic"}},"spec": {"volumes":[ ...

further more shorter url works fine

url = 'http://10.69.117.136:8080/api/v1/namespaces/'
json = requests.get(url)
print json.content

{"kind":"NamespaceList","apiVersion":"v1","metadata":{"selfLink":"/api/v1/namespaces/","resourceVersion":"220452"},"items":[{"metadata":{"name":"default","selfLink":"/api/v1/namespaces/default","uid":"74f89440-a94a-11e5-9afd-0050569761f2","resourceVersion":"6","creationTimestamp":"2015-12-23T07:54:55Z"},"spec":{"finalizers":["kubernetes"]},"status":{"phase":"Active"}}]}

where did i wrong?

1
Try using a raw string url = r'http:// <-- note the r in frontOneCricketeer
i tried, but raw string doesn't work :(. As the answer from Jan Vlcinsky, by deleting the quotes around "default" works :) anyway thanks a lot!Zhi Yuan

1 Answers

1
votes

Making the request from requests and from command line sends it to different urls.

The requests request from Python code really tries to use url including the quotes.

curl from command line does strip the quotes (in other cases it escapes the quotes).

I am unable to test your real url for real requests, but I guess, that following might work:

url = 'http://10.69.117.136:8080/api/v1/namespaces/default/pods/tas-core/'
json = requests.get(url)
print json.content