Skip to content

importing the requests module #1163

Answered by FabioRosado
visjble asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @visjble thank you for creating this discussion!

There are a few different ways you can do this. If you want to use requests you can install pyodide-http and patch requests. Here's an example code of what I mean:

<py-config>
packages = ["requests",  "pyodide-http"]
</py-config>

<py-script>
import pyodide_http
pyodide_http.patch_all()

import requests
url = 'https://jsonplaceholder.typicode.com/posts/2'
data = requests.get(url)
print(data)
</py-script>

This is the easiest way to do it. Alternatively, you can create your own requests module following the great guide created by @JeffersGlass - How to make HTTP requests using PyScript, in pure Python.

Please let us know if this solves …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@FabioRosado
Comment options

@visjble
Comment options

Answer selected by visjble
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants