tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

Wrong type argument: char-or-string-p ...the url... #131

Closed ShuguangSun closed 5 years ago

ShuguangSun commented 5 years ago

When I updated to the newest request from melpla, it raise the error message:

error in process sentinel: let: Wrong type argument: char-or-string-p, http://www\.the\.url...
error in process sentinel: Wrong type argument: char-or-string-p, http://www\.the\.url...

When I revised the following changes recently, it comes back to work again. So that I think the changes below is not robust.

    (let* ((scheme (url-type (url-generic-parse-url
                              (request-response-url response))))
           (curl-file-p (and (stringp scheme)
                            (not (string-match-p "^http" scheme))
                            (eq (request-response--backend response) 'curl))))
      ;; curl does not add a header for say file:///foo/bar
      (unless curl-file-p
        (request--clean-header response)
        (request--cut-header response)))
dickmao commented 5 years ago

Are you calling (request 'http://www.the.url) instead of (request "http://www.the.url")?

If not, it would be nice to have your original request call that produces the error.

ShuguangSun commented 5 years ago

For example

(request
 "http://httpbin.org/get"
 :params '(("key" . "value") ("key2" . "value2"))
 :parser 'json-read
 :success (cl-function
           (lambda (&key data &allow-other-keys)
             (message "I sent: %S" (assoc-default 'args data)))))

Below is my Emacs information.

In GNU Emacs 27.0.50 (build 3, x86_64-w64-mingw32)
 of 2019-07-28 built on 
Repository revision: efc6301068b53ab319aa6a8a1b5607273e4d5b17
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.17763
System Description: Microsoft Windows 10 Enterprise (v10.0.1809.17763.615)
dickmao commented 5 years ago

It's a mystery. Can you isolate the latest request.el into /tmp and execute the following:

emacs-27.0.50 -Q --batch -l /tmp/request.el --eval "(request \"http://httpbin.org/get\" :sync t :params '((\"key\" . \"value\") (\"key2\" . \"value2\")) :parser 'json-read :success (cl-function (lambda (&key data &allow-other-keys) (message \"I sent: %S\" (assoc-default 'args data)))))"
ShuguangSun commented 5 years ago

In Eamcs -Q, it is only REQUEST [error] Error (error) while connecting to http://httpbin.org/get.

ShuguangSun commented 5 years ago

(print (type-of (request-response-url response))) will print symbol

I set the log and message to trace, it shows that the first several steps success and get the data, however the callback raise the error.

dickmao commented 5 years ago

I don't know at what point (request-response-url response) changes from a string to a symbol, so in f466ab1 merely avoid the curl-file-p check if it's a symbol. Sorry about this.

ShuguangSun commented 5 years ago

It seems the (setf (request-response-url response) url-effective) in request--curl-callback changes the type, and the url-effective is a symbol.

dickmao commented 5 years ago

Indeed, this is not something I tested. Thank you for your help.