@brentgordon146 Do you have a link to relevant source code I can look at?
@deactivateduser60718
If I’m reading this right, that output comes from upload-image
and the service endpoint you are hitting responds with JSON. The JSON has an errors
key holding a message that just so happens to (semantically) disagree with the 400
status code from the response headers. As for why that is, I couldn’t say without seeing the actual server implementation.
the server im sending a request to is using nginx
One comment though: It looks like (download-image)
may return a Racket string that pass as-is via #:data
. Did you verify that the string is being encoded as expected?
no i dont know how to do that
I can’t say for sure yet, but my suspicion is that your argument to #:data
might not be proper for a file upload
@jeapostrophe ^ did I get that right?
Yeah that post is what I’ve been using as a guide
In that case I’m not seeing bytes-append
or ->bytes
when i (displayln (download-image)) i dont see the content-disposition and the content-type headers
That’s because it’s not returning what you expect
I dont why they did bytes-append and ->bytes is a function they defined that just appends string as far as i see
So, two things here:
- A string is just Racket’s representation of characters under a certain encoding (99% of the time that’s UTF–8). HTTP deals in bytes. Some HTTP helpers will convert strings to bytes for you, but they won’t always be equivalent (such as if your headers say you are using a different encoding, or if the server expects a different encoding).
- If I reformat your code, I get this:
(define (download-image)
(define post (search-safebooru))
(define url (hash-ref post 'file_url))
(define md5 (hash-ref post 'md5))
(define file-ext (hash-ref post 'file_ext))
(define filename (string-append md5 "." file-ext))
(call-with-output-file filename
(lambda (in) (display (port->bytes (get-pure-port (string->url url)))in))
#:exists 'replace)
(define image (file->bytes filename))
(define data
(string-append
CRLF "--" boundary CRLF "Content-Disposition: form-data; name=\"file\"; filename="
(string-append "\"" filename "\"") CRLF
(string-append "Content-Type: image/"
(if (eq? file-ext "jpg") "jpeg" "png") CRLF)))
image
(string-append CRLF "--" boundary "--" CRLF))
In the paste, it looks like data
ends up being ignored and discarded.
You’re only returning (string-append CRLF "--" boundary "--" CRLF)
ah silly me
Heads up: Your access token is visible in the screenshot (:+1: on the deletion!)
so im still stumped
nono matter what i send i get internal server error
Do you have docs for the server?
Alright, so looking at this you already know you are making a multipart form data request. Give me a few minutes to think about your code.
@brentgordon146 I haven’t tested this, obviously. But tell me what happens if bot.rkt
looks like this: https://pastebin.com/GiCDCxGM
I forgot a CLRF after "Content-Disposition: form-data; name=\"file\";"
, so put one in first
still internal server errror
I have a few blind spots so I’m unsure if the bug is in the client or server. One thing you can do to check is to follow an answer like https://stackoverflow.com/a/20593879/394397 to write a handler to see if you can accept the file at all.
If the handler cannot accept the file, then the request is probably not formatted correctly. If the handler can accept the file, then a request header is probably incorrect for the Mastodon instance.
It looks like css-expr
is no longer being maintained, but I just discovered a fun fact about it.
#lang racket
(provide css)
(require css-expr)
(define css (css-expr->css (css-expr
[header
#:
#:background-color \|#06a\|])))
This is invalid because of the blank keyword, and the library will complain. So far so good, right?
Well, if you add two correct @font-face
declarations in front (see snippet below), the module will actually never finish instantiating
So… The first code block will immediately raise an exception. The second code block with the same mistake will get caught in an infinite loop.
BUT, if you remove EITHER of the @font-face
declarations, it’s fine again.
:man-shrugging:
@me1419 has joined the channel
I’ve had an idea floating around in my head. Would it be possible to specify a minimal ABI (I’m not sure if this is the right term) that would implement the core of Racket (or any given language) and which could be use by another program to generate a Racket interpreter/compiler?
I’m not sure what the applications of this would be. The idea came to me from typeclasses in Haskell, and the fact that a new type can be made to implement a typeclass by implementing a minimal set of functions.
My initial answer to myself is “I don’t see why not”. So I guess I would be most interested in thoughts about why not if not and thoughts about possible applications. The obvious consequence is to enable a language to have different “backends”. The question then becomes: [how] is this useful?
Your idea sounds a lot like an intermediate representation, such as LLVM
Good point.
I would say about my idea that an intermediate representation would be used to implement the minimal interface. The choice of intermediate representation is open.
Conversely choosing an intermediate representation leaves the choice of how to express the target language open.
You’ve made me realize though that my choice of the term ABI is too narrow. There is no reason why the end result of what I’m describing should be binary. The end result could be in any language. The only requirement would be compiler from the implementation language into the target language.
I am starting to get the impression that what I’m saying is not all that useful.