Can I use Requests library in a Python Worker

Ok, I don't remember where I read it, but I thought I could use the Requests library to do GET and POST requests. But, I'm getting ModuleNotFoundError: No module named 'requests' error.
4 Replies
Cyb3r-Jak3
Cyb3r-Jak37mo ago
No. You can use something like aiohttp or httpx
Tòónz ඞ
Tòónz ඞOP7mo ago
FOUND IT
Tòónz ඞ
Tòónz ඞOP7mo ago
Here it mentions requests: 2.31.0 https://developers.cloudflare.com/workers/languages/python/packages/ Does that not mean that it can support it, or am I doing a very obviously dumb thing...
Cloudflare Docs
Python packages supported in Cloudflare Workers · Cloudflare Worker...
You can currently only use built-in packages in local development. Support for deploying packages with a requirements.txt file is coming soon.
Tòónz ඞ
Tòónz ඞOP7mo ago
THE PLOT THICKENS, haha... I have no idea what I'm doing lol
GET / 500 Internal Server Error (925ms)
✘ [ERROR] Error in makeHandler


✘ [ERROR] TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)
at async Promise.all (index 2)
at async loadPackages (pyodide-internal:loadPackage:79:19)
at null.<anonymous> (async pyodide:python-entrypoint-helper:87:5)
at async setupPackages (pyodide:python-entrypoint-helper:85:10)
at null.<anonymous> (async pyodide:python-entrypoint-helper:113:7)
at async preparePython (pyodide:python-entrypoint-helper:129:22)
at null.<anonymous> (async pyodide:python-entrypoint-helper:139:21)
at async Object.fetch (pyodide:python-entrypoint-helper:137:26)


✘ [ERROR] Uncaught (in promise) TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)


✘ [ERROR] Uncaught (in response) TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)
at async Promise.all (index 2)
at async loadPackages (pyodide-internal:loadPackage:79:19)
at async pyodide:python-entrypoint-helper:87:5
at async setupPackages (pyodide:python-entrypoint-helper:85:10)
at async pyodide:python-entrypoint-helper:113:7
at async preparePython (pyodide:python-entrypoint-helper:129:22)
at async pyodide:python-entrypoint-helper:139:21
at async Object.fetch (pyodide:python-entrypoint-helper:137:26)
GET / 500 Internal Server Error (925ms)
✘ [ERROR] Error in makeHandler


✘ [ERROR] TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)
at async Promise.all (index 2)
at async loadPackages (pyodide-internal:loadPackage:79:19)
at null.<anonymous> (async pyodide:python-entrypoint-helper:87:5)
at async setupPackages (pyodide:python-entrypoint-helper:85:10)
at null.<anonymous> (async pyodide:python-entrypoint-helper:113:7)
at async preparePython (pyodide:python-entrypoint-helper:129:22)
at null.<anonymous> (async pyodide:python-entrypoint-helper:139:21)
at async Object.fetch (pyodide:python-entrypoint-helper:137:26)


✘ [ERROR] Uncaught (in promise) TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)


✘ [ERROR] Uncaught (in response) TypeError: response.body.arrayBuffer is not a function

at loadBundle (pyodide-internal:loadPackage:36:36)
at async Promise.all (index 2)
at async loadPackages (pyodide-internal:loadPackage:79:19)
at async pyodide:python-entrypoint-helper:87:5
at async setupPackages (pyodide:python-entrypoint-helper:85:10)
at async pyodide:python-entrypoint-helper:113:7
at async preparePython (pyodide:python-entrypoint-helper:129:22)
at async pyodide:python-entrypoint-helper:139:21
at async Object.fetch (pyodide:python-entrypoint-helper:137:26)
So, this error occurs when I put requests in requirements.txt. Doesn't matter if I import requests or not. Ok... No matter whatever package I put in requirements.txt it still gives me that. This is the code in index.py
from js import Response

def on_fetch(request):
print("Hi there!")
return Response.new("Hello World!")
from js import Response

def on_fetch(request):
print("Hi there!")
return Response.new("Hello World!")
And this is what's in requirements.txt
httpx
httpx
And this is the Error
TypeError: response.body.arrayBuffer is not a function
at async Object.fetch (.../Worker/node_modules/miniflare/dist/src/workers/core/entry.worker.js:1024:22)
TypeError: response.body.arrayBuffer is not a function
at async Object.fetch (.../Worker/node_modules/miniflare/dist/src/workers/core/entry.worker.js:1024:22)
Want results from more Discord servers?
Add your server