deactivateduser60718
2020-2-13 15:01:34

@brentgordon146 Do you have a link to relevant source code I can look at?


brentgordon146
2020-2-13 15:21:24

brentgordon146
2020-2-13 15:22:06

@deactivateduser60718


deactivateduser60718
2020-2-13 16:05:33

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.


brentgordon146
2020-2-13 16:08:52

the server im sending a request to is using nginx


deactivateduser60718
2020-2-13 16:08:55

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?


brentgordon146
2020-2-13 16:09:48

no i dont know how to do that



deactivateduser60718
2020-2-13 16:13:18

I can’t say for sure yet, but my suspicion is that your argument to #:data might not be proper for a file upload


deactivateduser60718
2020-2-13 16:13:44

@jeapostrophe ^ did I get that right?


brentgordon146
2020-2-13 16:14:21

Yeah that post is what I’ve been using as a guide


deactivateduser60718
2020-2-13 16:16:16

In that case I’m not seeing bytes-append or ->bytes


brentgordon146
2020-2-13 16:16:28

when i (displayln (download-image)) i dont see the content-disposition and the content-type headers


deactivateduser60718
2020-2-13 16:17:40

That’s because it’s not returning what you expect


brentgordon146
2020-2-13 16:17:52

I dont why they did bytes-append and ->bytes is a function they defined that just appends string as far as i see


deactivateduser60718
2020-2-13 16:18:14

So, two things here:


deactivateduser60718
2020-2-13 16:19:16
  1. 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).

deactivateduser60718
2020-2-13 16:20:32
  1. If I reformat your code, I get this:

deactivateduser60718
2020-2-13 16:20:35

(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))


deactivateduser60718
2020-2-13 16:21:07

In the paste, it looks like data ends up being ignored and discarded.


deactivateduser60718
2020-2-13 16:21:45

You’re only returning (string-append CRLF "--" boundary "--" CRLF)


brentgordon146
2020-2-13 16:24:13

ah silly me


deactivateduser60718
2020-2-13 16:25:08

Heads up: Your access token is visible in the screenshot (:+1: on the deletion!)


brentgordon146
2020-2-13 16:26:36

so im still stumped


brentgordon146
2020-2-13 16:26:53

nono matter what i send i get internal server error


deactivateduser60718
2020-2-13 16:27:08

Do you have docs for the server?



deactivateduser60718
2020-2-13 16:34:16

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.


deactivateduser60718
2020-2-13 16:48:08

@brentgordon146 I haven’t tested this, obviously. But tell me what happens if bot.rkt looks like this: https://pastebin.com/GiCDCxGM


deactivateduser60718
2020-2-13 16:50:05

I forgot a CLRF after "Content-Disposition: form-data; name=\"file\";", so put one in first


brentgordon146
2020-2-13 16:53:20

still internal server errror


deactivateduser60718
2020-2-13 16:56:30

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.


deactivateduser60718
2020-2-13 16:57:13

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.


deactivateduser60718
2020-2-13 19:42:55

It looks like css-expr is no longer being maintained, but I just discovered a fun fact about it.


deactivateduser60718
2020-2-13 19:43:40

#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?


deactivateduser60718
2020-2-13 19:44:05

Well, if you add two correct @font-face declarations in front (see snippet below), the module will actually never finish instantiating


deactivateduser60718
2020-2-13 19:44:47

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.


deactivateduser60718
2020-2-13 19:45:01

BUT, if you remove EITHER of the @font-face declarations, it’s fine again.


deactivateduser60718
2020-2-13 19:45:53

deactivateduser60718
2020-2-13 19:46:28

:man-shrugging:


me1419
2020-2-13 20:07:18

@me1419 has joined the channel


ruyvalle
2020-2-14 02:03:49

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.


ruyvalle
2020-2-14 02:10:36

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?


samth
2020-2-14 02:46:18

Your idea sounds a lot like an intermediate representation, such as LLVM


ruyvalle
2020-2-14 03:03:28

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.