Request.el“无法创建与api.stackexchange.com的连接" [英] Request.el "cannot create connection to api.stackexchange.com"

查看:49
本文介绍了Request.el“无法创建与api.stackexchange.com的连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 request.el 库(可通过MELPA获得)进行尝试并创建一个基本框架,从该框架开始认真地在 Emacs的堆栈交换模式上工作.我要做的就是能够将json-read所解析的对象返回给调用函数,但是我什至似乎都无法建立连接.

I'm using the request.el library (available via MELPA) to try and create a basic framework from which to start work in earnest on a Stack Exchange mode for Emacs. All I want to do is to be able to return the object as parsed by json-read to the calling function, but I can't even seem to make a connection.

我知道要让我的函数返回该对象,必须同步进行该调用,因此:sync t就可以了.我已经考虑过使其成为异步调用,但是考虑到它的用例,我认为这不会有所帮助.

I understand that to have my function return the object, the call must be made synchronously, so that is what :sync t is there for. I've considered making it an asynchronous call, but I don't think it would be beneficial considering its use-case.

首先,当我查看消息后,我以为也许我没有必要的二进制文件".我确实用它的文档附带的一些示例调用测试了request.el,并且它们工作正常,所以就可以了.

At first, after I looked at the messages, I thought 'Maybe I don't have necessary binaries.' I did test request.el with some example calls that come with its documentation, and they work fine, so that's out.

我茫然不知所措.我在处理网络方面还没有足够的经验(无论成功与否),也没有完全理解我收到的错误消息.据我所知,API的端口443给了我静默的待遇,但我很犹豫;)的情况.

I'm at a loss as to what is wrong. I don't yet have much experience, successful or otherwise, with anything dealing with a network, and don't fully understand the error message I'm getting. As far as I can tell, port 443 of the API is giving me the silent treatment, but I'm hesitant to think that's the case ;).

;; Works like a charm
(defun alist-to-json (alist)
  "Converts the key-value pairs of `ALIST` into a JSON-friendly
string: \"key1=value1&key2=value2&\"."
  (apply 'concat
     (mapcar (lambda (kv)
               (format "%s=%s&" (car kv)
                       (if (stringp (cdr kv)) 
                           (cdr kv)
                         (number-to-string (cdr kv)))))
             alist)))


(defvar stack-api-root "https://api.stackexchange.com/2.1/")

(require 'json)
(require 'request)

(defun stack-api-request (call keys-alist)
  "Makes the specified `CALL` to the Stack Exchange API with the
  key-value pairs given `KEYS-ALIST`.  For example,

  (stack-api-request \"sites\" '((page . 2) (page_size . 25)))"

  (let* ((base-call (concat stack-api-root call "?"))
         (options (alist-to-json keys-alist)))
    (request base-call
     :params options
     :parser 'json-read
     :sync t)))

回溯

Debugger entered--Lisp error: (error "Could not create connection to api.stackexchange.com:443")
  signal(error ("Could not create connection to api.stackexchange.com:443"))
  error("Could not create connection to %s:%d" "api.stackexchange.com" 443)
  url-http([cl-struct-url "https" nil nil "api.stackexchange.com" nil "/2.1/sites?&" nil nil t nil t] #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil))
  url-https([cl-struct-url "https" nil nil "api.stackexchange.com" nil "/2.1/sites?&" nil nil t nil t] #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil))
  url-retrieve-internal("https://api.stackexchange.com/2.1/sites?&" #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"] (nil) nil nil)
  url-retrieve("https://api.stackexchange.com/2.1/sites?&" #[128 "\302\303\304p#\210\300\305\240\210\301p\240\207" [(nil) (nil) url-debug retrieval "Synchronous fetching done (%S)" t] 5 "\n\n(fn &rest IGNORED)"])
  url-retrieve-synchronously("https://api.stackexchange.com/2.1/sites?&")
  request--url-retrieve-sync("https://api.stackexchange.com/2.1/sites?&" :params "page=2&page_size=25&" :parser json-read :sync t :error (closure (t) (&rest args) (apply (quote request-default-error-callback) (quote "https://api.stackexchange.com/2.1/sites?") args)) :url "https://api.stackexchange.com/2.1/sites?&" :response [cl-struct-request-response nil nil nil nil nil "https://api.stackexchange.com/2.1/sites?&" nil (:params "page=2&page_size=25&" :parser json-read :sync t :error (closure (t) (&rest args) (apply (quote request-default-error-callback) (quote "https://api.stackexchange.com/2.1/sites?") args)) :url "https://api.stackexchange.com/2.1/sites?&" :response #0) nil nil nil url-retrieve nil])
  apply(request--url-retrieve-sync "https://api.stackexchange.com/2.1/sites?&" (:params "page=2&page_size=25&" :parser json-read :sync t :error (closure (t) (&rest args) (apply (quote request-default-error-callback) (quote "https://api.stackexchange.com/2.1/sites?") args)) :url "https://api.stackexchange.com/2.1/sites?&" :response [cl-struct-request-response nil nil nil nil nil "https://api.stackexchange.com/2.1/sites?&" nil #0 nil nil nil url-retrieve nil]))
  request("https://api.stackexchange.com/2.1/sites?" :params "page=2&page_size=25&" :parser json-read :sync t)
  (let* ((base-call (concat stack-api-root call "?")) (options (alist-to-json keys-alist))) (request base-call :params options :parser (quote json-read) :sync t))
  stack-api-request("sites" ((page . 2) (page_size . 25)))
  eval((stack-api-request "sites" (quote ((page . 2) (page_size . 25)))) nil)
  eval-expression((stack-api-request "sites" (quote ((page . 2) (page_size . 25)))) nil)
  call-interactively(eval-expression nil nil)

消息:

Contacting host: api.stackexchange.com:443
Opening TLS connection to `api.stackexchange.com'...
Opening TLS connection with `gnutls-cli --insecure -p 443 api.stackexchange.com'...failed
Opening TLS connection with `gnutls-cli --insecure -p 443 api.stackexchange.com --protocols ssl3'...failed
Opening TLS connection with `openssl s_client -connect api.stackexchange.com:443 -no_ssl2 -ign_eof'...failed
Opening TLS connection to `api.stackexchange.com'...failed


我已检查,以确保这不是cURL的问题.我用于curl的电话是


I checked to make sure that this was not a problem with cURL. The call I use for curl is

curl api.stackexchange.com/2.1/sites --compressed

从外部查看request存储库,request也在执行此操作.我不知道怎么回事.

From the outside looking into the request repository, request is doing this as well. I don't know what could be going wrong.

推荐答案

我将您的示例简化为以下代码段,以重现您的问题,但它确实有效.你可以试试这个吗?

I boiled down your example to the following snippet to reproduce your problem but it actually worked. Can you try this one?

(request
 "http://api.stackexchange.com/2.1/sites"
 :parser 'json-read
 :params '((page . "2") (page_size . "25"))
 :success (lambda (&rest args) (princ (plist-get args :data))))

它应该将一些数据打印到*Messages*缓冲区和回显区域.

It should print some data to *Messages* buffer and echo area.

您的示例中的问题似乎是您正在将字符串传递给仅包含列表的PARAMS.我将更改代码以引发错误,以便更轻松地进行调试.

It seems that the problem in your example is that you are passing string to PARAMS which takes only alist. I will change code to raise error so that it is easier to debug.

这篇关于Request.el“无法创建与api.stackexchange.com的连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆