lightbug_http icon indicating copy to clipboard operation
lightbug_http copied to clipboard

Unable to run the given client example

Open thomas-huegel opened this issue 7 months ago • 2 comments

Describe the bug

.magic/envs/default/lib/mojo/lightbug_http.mojopkg:0:0: error: unknown attribute code: 36
src/main.mojo:2:6: error: failed to materialize top-level module
from lightbug_http.client import Client
     ^
src/main.mojo:2:20: error: 
from lightbug_http.client import Client
                   ^
mojo: error: failed to parse the provided Mojo source module

To Reproduce

from lightbug_http import *
from lightbug_http.client import Client

fn test_request(mut client: Client) raises -> None:
    var uri = URI.parse("google.com")
    var headers = Headers(Header("Host", "google.com"))
    var request = HTTPRequest(uri, headers)
    var response = client.do(request^)

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

    print(response.headers)

    print(
        "Is connection set to connection-close? ", response.connection_close()
    )

    # print body
    print(to_string(response.body_raw))


fn main() -> None:
    try:
        var client = Client()
        test_request(client)
    except e:
        print(e)

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Linux x64
  • mojo 25.2.0
  • lightbug_http 0.1.14

thomas-huegel avatar Apr 21 '25 14:04 thomas-huegel

@thomas-huegel I was able to reproduce this, seems to do with the small_time dependency. Currently working on including small_time directly, not over magic, hopefully this solves the issue. Will post here when done

saviorand avatar Apr 22 '25 18:04 saviorand

I shipped some changes in 0.1.19 , now this works on Mac, but I'm getting the following on Linux:

 magic run mojo test.mojo 
/workspaces/codespaces-blank/life/.magic/envs/default/lib/mojo/lightbug_http.mojopkg:0:0: error: unexpected trailing bytes after Attribute entry
/workspaces/codespaces-blank/life/test.mojo:2:6: error: failed to materialize top-level module
from lightbug_http.client import Client
     ^
/workspaces/codespaces-blank/life/test.mojo:2:20: error: 
from lightbug_http.client import Client
                   ^
/workspaces/codespaces-blank/life/.magic/envs/default/bin/mojo: error: failed to parse the provided Mojo source module

Will try to investigate

saviorand avatar Apr 23 '25 06:04 saviorand

@thomas-huegel I think it's fixed now!

Works for me now. Here's how I tested this:

  1. Set up a blank Github Codespace (I think it's running Ubuntu),
  2. install Mojo 25.3.0
  3. Follow the instructions in the Lightbug README to add the latest Lightbug version (also 25.3.0, we switched to the same versioning as MAX) as a dependency
  4. Add a client.mojo file with the code you shared
  5. Run magic run mojo client.mojo

Let me know if this is fixed for you now as well. Will close for now and reopen in case you'll report the issue persists

saviorand avatar Jun 05 '25 17:06 saviorand

It now works, thanks!

thomas-huegel avatar Jun 06 '25 08:06 thomas-huegel