Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the PythonClient Throws a Compilation Error #41

Closed
saviorand opened this issue May 21, 2024 · 11 comments
Closed

Running the PythonClient Throws a Compilation Error #41

saviorand opened this issue May 21, 2024 · 11 comments

Comments

@saviorand
Copy link
Collaborator

As reported by Logan logan100 on Discord:

Describe the bug
An error is thrown when trying to run the PythonClient, sending a request to httpbin:

➜  MojoTesting git:(main) ✗ mojo main.🔥
/Users/logan/Documents/MojoTesting/lightbug_http.📦:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@http::@HTTPRequest::@"__del__(lightbug_http::http::HTTPRequest)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@http::@HTTPRequest, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.📦:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@uri::@URI::@"__del__(lightbug_http::uri::URI)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@uri::@URI, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.📦:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@python::@client::@PythonClient::@"__del__(lightbug_http::python::client::PythonClient)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@python::@client::@PythonClient, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.📦:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@header::@RequestHeader::@"__del__(lightbug_http::header::RequestHeader)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@header::@RequestHeader, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>

To Reproduce
Run the client like below

from lightbug_http.http import HTTPRequest
from lightbug_http.uri import URI
from lightbug_http.python.client import PythonClient
from lightbug_http.header import RequestHeader


fn test_request_simple_url(inout client: PythonClient) raises -> None:
    """
    Test making a simple GET request without parameters.
    Validate that we get a 200 OK response.
    """
    var uri = URI("http://httpbin.org/status/200")
    var request = HTTPRequest(uri)
    var response = client.do(request)
    print(response.header.status_code())


fn main() raises -> None:
    var client = PythonClient()
    test_request_simple_url(client)

Expected behavior
The client should make a successful request to the endpoint specified and receive a response.

@saviorand
Copy link
Collaborator Author

saviorand commented May 21, 2024

I think there was a regression on main after #40 , I should definitely add a proper test suite to run in the CI to know when this happens...

The code below, similar to how you tried it before, should now work. Don't forget to pull the latest changes. Will add the example code for running the client to the README.

PythonClient is still throwing compile errors, but this is related to another issue -- If MojoClient works for you I'll close those in favor of #34 . Let me know if you have any questions!

from lightbug_http.http import HTTPRequest
from lightbug_http.uri import URI
from lightbug_http.sys.client import MojoClient

fn test_request_simple_url(inout client: MojoClient) raises -> None:
    """
    Test making a simple GET request without parameters.
    Validate that we get a 200 OK response.
    """
    var uri = URI("http://httpbin.org/status/200")
    var request = HTTPRequest(uri)
    var response = client.do(request)
    
    # print status code
    print(response.header.status_code())
    
    # print various parsed headers
    print(response.header.content_length())
    
    # print body
    # print(String(response.get_body()))


fn main() raises -> None:
    var client = MojoClient()
    test_request_simple_url(client)

@Logan9312
Copy link

Logan9312 commented May 22, 2024

I tried running this code, but it's behaving very strange. This is using the pkg file from the latest release

from lightbug_http.http import HTTPRequest
from lightbug_http.uri import URI
from lightbug_http.sys.client import MojoClient

fn test_request_simple_url(inout client: MojoClient) raises -> None:
    """
    Test making a simple GET request without parameters.
    Validate that we get a 200 OK response.
    """
    var uri = URI("http://httpbin.org/status/200")
    var request = HTTPRequest(uri)
    var response = client.do(request)

    # print status code
    print("Response:", response.header.status_code())

    # print various parsed headers
    print("Header", response.header.content_length())

    # print body
    print(String(response.get_body()))


fn main() raises -> None:
    var client = MojoClient()
    print("Testing URL request")
    test_request_simple_url(client)
    print("Done")

This is the output I get:

mojo main.🔥
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@http::@HTTPRequest::@"__del__(lightbug_http::http::HTTPRequest)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@http::@HTTPRequest, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@uri::@URI::@"__del__(lightbug_http::uri::URI)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@uri::@URI, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@sys::@client::@MojoClient::@"__del__(lightbug_http::sys::client::MojoClient)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@sys::@client::@MojoClient, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
Testing URL request
Done

It's not even printing anything for some reason in the test function

@saviorand
Copy link
Collaborator Author

@Logan9312 hmm I see, cannot reproduce this one on my Mac M1 using this latest package. Will try on a Linux machine later today.

@saviorand
Copy link
Collaborator Author

@Logan9312 hmm, couldn't reproduce on Linux as well. Could you share more details about your setup? Can you maybe try removing everything and creating a clean setup with the latest package + code you shared? Will appreciate anything that can help reproduce this. Thanks!

@saviorand
Copy link
Collaborator Author

Added a section in the README on using the client, see here: https://github.com/saviorand/lightbug_http?tab=readme-ov-file#using-the-client

@Logan9312
Copy link

Logan9312 commented May 25, 2024

@Logan9312 hmm I see, cannot reproduce this one on my Mac M1 using this latest package. Will try on a Linux machine later today.

Using the package you linked here, I downloaded it and put it into the top level alongside a main.🔥 file.

The main file only contained the code you put in the README:

from lightbug_http.http import HTTPRequest
from lightbug_http.uri import URI
from lightbug_http.sys.client import MojoClient

fn test_request(inout client: MojoClient) raises -> None:
    var uri = URI("http://httpbin.org/")
    var request = HTTPRequest(uri)
    var response = client.do(request)

    # print status code
    print("Response:", response.header.status_code())

    # print various parsed headers
    print("Header", response.header.content_length())

    # print body
    print(String(response.get_body()))


fn main() raises -> None:
    var client = MojoClient()
    test_request(client)

My setup is on an M2 Macbook air. Mojo version is mojo 2024.5.1905 (46b7e7ee).

When running by doing mojo main.🔥 I get the following response:

➜  MojoTesting mojo main.🔥
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@http::@HTTPRequest::@"__del__(lightbug_http::http::HTTPRequest)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@http::@HTTPRequest, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@uri::@URI::@"__del__(lightbug_http::uri::URI)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@uri::@URI, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected mlir::StringAttr, but got: #kgen.symbol.constant<@lightbug_http::@sys::@client::@MojoClient::@"__del__(lightbug_http::sys::client::MojoClient)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@sys::@client::@MojoClient, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
➜  MojoTesting 

@saviorand
Copy link
Collaborator Author

Ah, I see. Thanks for the details. Was able to reproduce now after switching to the nightly version. I'll try to debug but in the meantime switching to the latest stable version (24.3) should help.

@Logan9312
Copy link

I got that version when running modular install mojo so I assumed it was the latest stable. When I run modular install nightly/mojo I get version mojo 2024.5.2514 (f472b8ac)

@saviorand
Copy link
Collaborator Author

saviorand commented May 28, 2024

@Logan9312 Can you try with this version? https://github.com/saviorand/lightbug_http/releases/tag/nightly-2805
Works for me now on the nightly. The PR is here: #51 , will merge after this nightly turns into a release version, so it doesn't break for folks on the current release version

@saviorand saviorand moved this to Backlog in Lightbug's Roadmap May 28, 2024
@saviorand saviorand moved this from Backlog to In review in Lightbug's Roadmap May 28, 2024
@Logan9312
Copy link

Logan9312 commented Jun 5, 2024

@saviorand Sorry for late response, but I tried that package and still get the following errors:

/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected M::KGEN::LIT::DocStringAttr, but got: #kgen.symbol.constant<@lightbug_http::@http::@HTTPRequest::@"__del__(lightbug_http::http::HTTPRequest)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@http::@HTTPRequest, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected M::KGEN::LIT::DocStringAttr, but got: #kgen.symbol.constant<@lightbug_http::@uri::@URI::@"__del__(lightbug_http::uri::URI)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@uri::@URI, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>
/Users/logan/Documents/MojoTesting/lightbug_http.mojopkg:0:0: error: expected M::KGEN::LIT::DocStringAttr, but got: #kgen.symbol.constant<@lightbug_http::@sys::@client::@MojoClient::@"__del__(lightbug_http::sys::client::MojoClient)"> : !kgen.signature<!lit.signature<[1]("self": !lit.ref<@lightbug_http::@sys::@client::@MojoClient, mut *[0,0]> owned_in_mem, |) -> !kgen.none>>

Seems like it doesn't even print the body. I'm wondering if this is maybe just a bug with mojo itself independent of the library?

@saviorand
Copy link
Collaborator Author

Removed the PythonServer and PythonClient in #61 due to this issue. If there's enough interest for a Python-based implementation can write a new one from scratch later

@github-project-automation github-project-automation bot moved this from In review to Done in Lightbug's Roadmap Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants