从 Emacs 访问 StackExchange API
我尝试从 Emacs 的 elisp 访问 StackExchange API:
(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)))
Mx read-json
导致以下错误:JSON readtable error
。
我错过了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这几乎肯定与 gzip 编码有关,原始服务器响应如下:
客户端似乎没有明确自愿支持 gzip(注意缺少 Accept-Encoding 标头),但服务器无论如何都会压缩响应。以下是运行代码时来自我的客户端的请求标头:
根据 HTTP 规范,服务器行为是可接受的:
如果您显式设置标头值,则会按预期返回响应:
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: