API request from server

How do I make an api request from the anvil lserver?

Normal python code would be:

import requests

x = requests.get(url, params = {“sentence”: “Elon Musk launches the Falcon around November despite failing multiple times reported The Times”})
print(x.text)

But from the Anvil docuemtnation I need to do something like this:

import anvil.http

resp = anvil.http.request(url)
print(f"Response MIME type: {resp.content_type}")

I can’t get that to work & I have parameters . .

Requests is in the set of server-side packages that you should be able to import.

Is it possible that you are using a limited Python runtime? These have fewer packages available for import.

1 Like

requests is available in Basic Python 3 too! If requests is what you’re used to, you can just use that, on the server side at least :slight_smile:

2 Likes

Thank you for the swift correction!