Sfoglia il codice sorgente

Merge pull request #263 from shobull/master

[zookeeper] Set default HTTP header to accept "application/json" in REST api
Romain Rigaux 10 anni fa
parent
commit
03971ea396
1 ha cambiato i file con 4 aggiunte e 2 eliminazioni
  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'])