I am trying to access the StackExchange API from Emacs’ elisp:
(require 'url)
(require 'json)
(defvar url-http-end-of-headers)
(defun read-json ()
(interactive)
(with-current-buffer (url-retrieve-synchronously "http://api.stackoverflow.com/0.8/users/2386")
(goto-char url-http-end-of-headers)
(json-read)))
M-x read-json results in the following error: JSON readtable error.
Am I missing anything?
This is almost certainly related to gzip encoding, the raw server response is as follows:
The client does not appear to be explicitly volunteering that it supports gzip (note the absence of the Accept-Encoding header), but the server is compressing the response anyways. Here are the request headers from my client when running your code:
The server behavior is acceptable according to the HTTP spec:
If you explicitly set the header value, the response is returned as expected: