fable-compiler / Fable.Python

Python bindings for Fable
https://fable.io/docs/
MIT License
135 stars 10 forks source link

Using System.Net.Http #88

Closed calwi closed 1 year ago

calwi commented 1 year ago

I'm trying to transpile a simple HTTP request with the HttpClient from System.Net.Http. Is this supported?

eg.

r "nuget: Fable.Python, 0.22.0"

r "nuget: Fable.Core, 3.7.1"

r "nuget: System.Net.Http, 4.3.4"

open System.Net.Http open System.IO open System.Threading

let getAsync (client:HttpClient) (url:string) = async { let! response = client.GetAsync(url) |> Async.AwaitTask response.EnsureSuccessStatusCode () |> ignore let! content = response.Content.ReadAsStringAsync() |> Async.AwaitTask return content }

let handler = new SocketsHttpHandler()

let client = new System.Net.Http.HttpClient(handler)

let content = getAsync (client) "https://github.com/fable-compiler/Fable.Python"

printfn "%s" (content |> Async.RunSynchronously) It just raises an exception in the Python

dbrattli commented 1 year ago

Hi, sorry but this is not supported. You would have to make a wrapper for Python libraries such as httpx or requests.

calwi commented 1 year ago

OK. Thanks Dag.