Browse Source

Update rest.py - set default http header to accept "application/json"

Zookeeper REST API return empty string without sending http header "Accept" "application/json" or "application/xml"
shobull 10 năm trước cách đây
mục cha
commit
07b78f6793
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      apps/zookeeper/src/zookeeper/rest.py

+ 4 - 2
apps/zookeeper/src/zookeeper/rest.py

@@ -171,8 +171,10 @@ class ZooKeeper(object):
     def _do_get(self, uri):
         """ Send a GET request and convert errors to exceptions """
         try:
-            req = urllib2.urlopen(uri)
-            resp = json.load(req)
+            req = urllib2.Request(uri)
+            req.add_header("Accept", "application/json");
+            r = urllib2.urlopen(req)
+            resp = json.load(r)
 
             if 'Error' in resp:
                raise ZooKeeper.Error(resp['Error'])