Inability to pass function parameters parsed from command line arguments

I have a function that uses Drakma to create a web page:

(defun scrape ()
  (let ((cookie-jar (make-instance 'drakma:cookie-jar)))
    (drakma:http-request "http://www.example.com/account/login"
             :method :post
             :parameters '(("username" . "myusername")
                       ("password" . "mypassword"))
             :cookie-jar cookie-jar)
    (setq body (drakma:http-request "http://www.example.com/"
                    :cookie-jar cookie-jar))
    (format t body)))

It works as I expect. However, if I parameterize the username and password as follows:

(defun scrape (username password)
  (let ((cookie-jar (make-instance 'drakma:cookie-jar)))
    (drakma:http-request "http://www.example.com/account/login"
             :method :post
             :parameters '(("username" . username)
                       ("password" . password))
             :cookie-jar cookie-jar)
    (setq body (drakma:http-request "http://www.example.com/"
                    :cookie-jar cookie-jar))
    (format t body)))

... and call it like this:

(scrape "my_username" "my_password")

... then I get the following error:

*** - Don't know what to do with name/value pair ("username" . USERNAME) in multipart/form-data body.

I am new to Lisp, so I am 100% sure that I am missing something very simple to use here. For instance. if I add a call to format the cleanup function, I see that the username is being transferred correctly.

+3
source share
2 answers

, , . , username upcased , , .

LIST CONS , , ..

(list (cons "username" username)
      (cons "password" password))

`(("username" . ,username)
  ("password" . ,password))
+2

parameters drakma:http-request , , alist, USERNAME PASSWORD. , , , . (list (cons "username" username) (cons "password" password)).

+1

Source: https://habr.com/ru/post/1783159/


All Articles