milindmadhukar / go-piston

A Wrapper of the Piston API in Golang
https://pkg.go.dev/github.com/milindmadhukar/go-piston
MIT License
10 stars 2 forks source link

not working with custom client (the new function) #1

Open jackrankin opened 3 weeks ago

jackrankin commented 3 weeks ago

This is basically the default code except I swapped in my own locally hosted Piston API. I get this error message: 2024/06/14 22:14:32 Unexpected Error. {"message":"requests must be of type application/json"}



import (
    "fmt"
    "log"
    "net/http"

    piston "github.com/milindmadhukar/go-piston"
)

func runCode() {
    h := http.DefaultClient
    client := piston.New("", h, "http://127.0.0.1:2000/api/v2/")

    execution, err := client.Execute("python", "",
        []piston.Code{
            {Content: "inp = input()\nprint(inp[::-1])"},
        },
        piston.Stdin("hello world"),
    )
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(execution.GetOutput())
}

func main() {
    runCode()
}
```c
milindmadhukar commented 2 weeks ago

Could be a missing header when making the request. Made a quick fix, can you test and let me know?