[drakma-devel] Error while trying to POST some JSON data
Peter Kuchta
peter at kuchta.co.uk
Thu Mar 21 21:54:49 UTC 2013
Kevin,
Thank you very much - I was absolutely sure I was doing something wrong!
Could you please show how I can roll back to cl+ssl-20130128-git ? I don't
know how to do it, I'm a quicklisp newbie.
Many thanks,
Piotr
On Thu, Mar 21, 2013 at 9:44 PM, Kevin Raison <raison at chatsubo.net> wrote:
> I encountered this same error after upgrading packages via quicklisp. I
> rolled back cl+ssl to version cl+ssl-20130128-git and the problem went
> away. I have not had time to investigate further yet.
>
> -Kevin
>
>
> On 03/21/2013 02:41 PM, Peter Kuchta wrote:
> > Hi everybody,
> >
> > I'm trying to POST some JSON data to a web service:
> >
> > (ql:quickload :st-json)
> > (ql:quickload :cl-json)
> > (ql:quickload :drakma)
> >
> > (defvar *rc* (merge-pathnames (user-homedir-pathname) ".apirc"))
> >
> > (defvar *user*
> > (with-open-file (s *rc*)
> > (st-json:read-json s)))
> >
> > (defvar api-url (st-json:getjso "url" *user*))
> > (defvar api-key (st-json:getjso "key" *user*))
> > (defvar api-email (st-json:getjso "email" *user*))
> >
> > (setf drakma:*header-stream* *standard-output*)
> >
> > (defvar *req* '(("dataset" . "tigge")
> > ("step" . "24")
> > ("date" . "20071001")
> > ("time" . "00")
> > ("origin" . "all")))
> >
> > (format t "json:~S~%" (json:encode-json-to-string *req*))
> >
> > (defun retrieve (api request)
> > (let* ((cookie-jar (make-instance 'drakma:cookie-jar))
> > (extra-headers (list (cons "From" api-email)
> > (cons "X-API-KEY" api-key)))
> > (url (concatenate 'string api-url api "/requests"))
> > (stream (drakma:http-request url
> > :additional-headers extra-headers
> > :accept "application/json"
> > :method :post
> > :content-type "application/json"
> > :external-format-out :utf-8
> > :external-format-in :utf-8
> > :redirect 100
> > :cookie-jar cookie-jar
> > :content (json:encode-json-to-string
> request)
> > :want-stream t)))
> > (st-json:read-json stream)))
> >
> > (retrieve "/datasets/tigge" *req*)
> >
> > Unfortunately, I get an error, although the data seems to be encoded OK
> > to JSON and the headers generated by drakma too, I think. Apparently
> > something is wrong with the :content (the list of integers in the errors
> > message is just the list of ASCII codes of the JSON encoded data).
> >
> >
> >
> json:"{\"dataset\":\"tigge\",\"step\":\"24\",\"number\":\"all\",\"levtype\":\"sl\",\"date\":\"20071001\",\"time\":\"00\",\"origin\":\"all\",\"type\":\"pf\",\"param\":\"tp\",\"area\":\"70\\/-130\\/30\\/-60\",\"grid\":\"2\\/2\",\"target\":\"data.grib\"}"
> >
> > POST /v1/datasets/tigge/requests HTTP/1.1
> > Host: api.service.int <http://api.service.int>
> > User-Agent: Drakma/1.3.0 (SBCL 1.1.5; Darwin; 12.2.0;
> > http://weitz.de/drakma/)
> > Accept: application/json
> > Connection: close
> > From: me at gmail.com <mailto:me at gmail.com>
> > X-API-KEY: 19a0edb6d8d8dda1e6a3b21223e4f86a
> > Content-Type: application/json
> > Content-Length: 193
> >
> >
> > debugger invoked on a SIMPLE-TYPE-ERROR:
> > The value of CL+SSL::THING is #(123 34 100 97 116 97 115 101 116
> > 34 58 34
> > ...), which is not of type
> (SIMPLE-ARRAY
> >
> > (UNSIGNED-BYTE 8)
> > (*)).
> >
> > Any idea what's wrong with this code? Many thanks in advance.
> >
> > Best regards,
> > Piotr
> >
> >
> > _______________________________________________
> > drakma-devel mailing list
> > drakma-devel at common-lisp.net
> > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/drakma-devel
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/drakma-devel/attachments/20130321/4428b403/attachment.html>
More information about the Drakma-devel
mailing list