0

Right now, when I do M-x package-refresh-contents I get: Failed to download Melpa archive

I tried toggling debug and doing the command again, and I get:

Debugger entered--Lisp error: (wrong-type-argument stringp \"https://melpa\.org/packages/\")
  string-match("\\`https?:" \"https://melpa\.org/packages/\" nil)
  package--with-response-buffer-1(\"https://melpa\.org/packages/\" #f(compiled-function () #<bytecode 0xec69cd>) :file "archive-contents" :async nil :error-function #f(compiled-function () #<bytecode 0xec69d$
  package--download-one-archive((\"melpa\" . \"https://melpa\.org/packages/\") "archive-contents" nil)
  package--download-and-read-archives(nil)
  package-refresh-contents()
  funcall-interactively(package-refresh-contents)
  call-interactively(package-refresh-contents record nil)
  command-execute(package-refresh-contents record)
  execute-extended-command(nil "package-refresh-contents" "package-refr")
  funcall-interactively(execute-extended-command nil "package-refresh-contents" "package-refr")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

I'm not sure how to parse this error.

I frequently have problems connecting with Melpa, but occasionally it does work without me having to change anything, so... I don't know.

In my .emacs file this is how I configured it:

(require 'package)
(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)

I really need to figure out why MELPA only works for me like 10% of the time... It's awesome when it works!

The question is: How do I get MELPA working consistently for me?

Emacs version 27.

3
  • 2
    Lose the backslashes in front of the double quotes.
    – NickD
    Commented Mar 22, 2022 at 19:08
  • @NickD Wow I feel so stupid haha. Thanks, that resolved the issue. If you want to post it as an answer I'll accept it. Embarrassing but maybe it could help someone else who made the same mistake.
    – cheryllium
    Commented Mar 23, 2022 at 17:21
  • I added some explanations in the answer - hope it's helpful.
    – NickD
    Commented Mar 23, 2022 at 19:03

1 Answer 1

1

String syntax in lisp is "this is a string": a string of characters in double quotes. If you want to include a double quote as part of the string, you have to escape it: "this is a string that include a \" character". That prevents the included double quote character from being interpreted as the closing quote that delimits the string. But conversely, \"abc\" is not a string, since it is not surrounded by double quotes: it is actually a symbol whose name is "abc".

Try evaluating the following forms to see the difference:


(symbolp '"abc")
nil
(stringp '"abc")
t

(symbolp '\"abc\")
t
(stringp '\"abc\")
nil

Since package-archives is a list of pairs, each pair consisting of two strings, not two symbols, you really need to say ...'("melpa" . "https://melpa.org/packages/") with the double quotes unescaped and acting as string delimiters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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