0

Q: How to retrieve a list of Github gists using url-retrieve-synchronously?

I am able to visit my gist list in a web browser:

https://api.github.com/users/lawlist/gists

When I try evaluating:

(url-retrieve-synchronously "https://api.github.com/users/lawlist/gists")

I get this:

Debugger entered--Lisp error: (error "Could not create connection to api.github.com:443")
signal(error ("Could not create connection to api.github.com:443"))
error("Could not create connection to %s:%d" "api.github.com" 443)
url-http(#s(url :type "https" :user nil :password nil :host "api.github.com" :portspec nil :filename "/users/lawlist/gists" :target nil :attributes nil :fullness t :silent nil :use-cookies t :asynchronous nil) #f(compiled-function (&rest ignored) #<bytecode 0x40e4195f>) (nil) nil tls)
url-https(#s(url :type "https" :user nil :password nil :host "api.github.com" :portspec nil :filename "/users/lawlist/gists" :target nil :attributes nil :fullness t :silent nil :use-cookies t :asynchronous nil) #f(compiled-function (&rest ignored) #<bytecode 0x40e4195f>) (nil))
url-retrieve-internal("https://api.github.com/users/lawlist/gists" #f(compiled-function (&rest ignored) #<bytecode 0x40e4195f>) (nil) nil nil)
url-retrieve("https://api.github.com/users/lawlist/gists" #f(compiled-function (&rest ignored) #<bytecode 0x40e4195f>) nil nil nil)
url-retrieve-synchronously("https://api.github.com/users/lawlist/gists")
eval((url-retrieve-synchronously "https://api.github.com/users/lawlist/gists") nil)
eval-expression((url-retrieve-synchronously "https://api.github.com/users/lawlist/gists") nil nil 127)
funcall-interactively(eval-expression (url-retrieve-synchronously "https://api.github.com/users/lawlist/gists") nil nil 127)
call-interactively(eval-expression nil nil)
command-execute(eval-expression)

Emacs Version: This is GNU Emacs 26.1 (build 1, x86_64-apple-darwin10.8.0, NS appkit-1038.36 Version 10.6.8 (Build 10K549)) of 2018-05-30


I have tried adding a username/password, but the result was similar:

(url-retrieve-synchronously "https://USERNAME:PASSWORD@api.github.com/users/lawlist/gists")
  • Your first suggestion seems to work for me. I get a buffer with HTTP output, the payload is some JSON starting with [{"url":"https://api.github.com/gists/303d3000eeb25d4885963ba5514e57d9","forks_url":"https://api.github.com/gists/303d3000eeb25d4885963ba5514e57d9/forks","... – npostavs Jun 28 at 1:46
  • @npostavs -- hmmm .... Yes, that is what the output should look like ... I'll try a different computer / OS and see if I have any better luck ... and I'll report back. – lawlist Jun 28 at 2:01
  • @npostavs -- Thank you for letting me know that you were able to get url-retrieve-synchronously to work on your end. After firing up a newer computer, I was also able to get a desired output. I answered this question with data regarding what version of OpenSSL was used to obtain the desired result. It sure would have been nice if Emacs could check the version and indicate what the problem was ..., but that may be asking for too much from Emacs ... – lawlist Jun 28 at 4:09
0

The computer that was used to run the test described in the question is running OpenSSL version 0.9.8r 8 Feb 2011.

Although I am uncertain what the minimum OpenSSL requirements are at this point in time, I was able to get the test to complete successfully with OpenSSL version 1.0.2g 1 Mar 2016.

I chose not to modify my default installation of OpenSSL so as to avoid opening a can of worms. Instead, I had a slightly newer version of OpenSSL installed through Macports a few years ago in a separate directory and I adjusted the path as follows:

(setq tls-program
  '("gnutls-cli --x509cafile %t -p %p %h"
    "gnutls-cli --x509cafile %t -p %p %h --protocols ssl3"
    "/absolute/path/openssl s_client -connect %h:%p -no_ssl2 -ign_eof"))

After evaluating the above snippet that utilizes the more recent version of OpenSSL mentioned above, evaluating the following:

(url-retrieve-synchronously "https://api.github.com/users/lawlist/gists")

produces a buffer named  *http api.github.com:443* containing the desired information.

  • AFAIK, tls-program should only matter if you haven't built with libgnutls. The use of external programs for tls (either gnutls-cli or openssl) is officially obsoleted in 27.1, see Bug#31457. And I wouldn't recommend it for earlier versions either since it can drop bytes randomly, see Bug#15905. – npostavs Jun 28 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.