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

requests #22

Open
andreagalle opened this issue Jun 9, 2023 · 5 comments
Open

requests #22

andreagalle opened this issue Jun 9, 2023 · 5 comments

Comments

@andreagalle
Copy link

I would like to make couple of API requests from my videogame written with pygame and pygbag, thus using the requests module.
After having added the neccessary import and the wheel in my own CDN I moved forward, but I still get different errors.

Once the requests module was available, it was looking for the urllib3 one. Once I put in place this one too, he is now screaming for the hmac one. I cannot find a wheel for the hmac since this should be automatically shipped with any python installation.

The error is here below, any suggestion on how to proceed? Even a brief explanation of how all this stuff works in WASM and how transitive/nested dependecies are managed would be helpful.

Hello from the pygame community. https://www.pygame.org/contribute.html
284: assets found : 0
341: EventTarget delayed by loader
/data/data/org.python/assets/site-packages/pygame/sysfont.py:235: UserWarning: no fc_cache font cache file at /data/data/src/assets/fc_cache
  warnings.warn(f"no fc_cache font cache file at {fc_cache}")
238: fc-cache: freesans {(True, False): '/data/data/org.python/assets/site-packages/pygame/freesansbold.ttf'}
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1020: import scan filename='<stdin>' len(code)=2411 ['requests']
1044: requesting module want='requests' for file='<stdin>' 
1055: module want='requests' requested
1204: want='requests' found : True
pkg : http://localhost:8030/archives/repo/pkg/requests-2.30.0-py3-none-any.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
646: starting shell
996: 89 lines queued for async eval
going interactive
643: TODO detect input/print to select repl debug
642: starting EventTarget in a few seconds

Python 3.11.1 (main, Jan  4 2023, 04:23:18) [Clang 16.0.0 (https://github.com/llvm/llvm-project 9ab0d4d66fa14a9c57864fea7259 on emscripten
Type "help", "copyright", "credits" or "license" for more information.
1204: want='urllib3' found : True
pkg : http://localhost:8030/archives/repo/pkg/urllib3-2.0.2-py3-none-any.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
resume=<function <module> at 0x5ead80> is not awaitable
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 3, in <module>
    import hmac
ModuleNotFoundError: No module named 'hmac'
@andreagalle
Copy link
Author

andreagalle commented Jun 9, 2023

The only package I need, working with plain pygame (without pygbag) is requests: here I don't need to explicitly import urllib3 nor hmac. Why?

@andreagalle
Copy link
Author

Even changing the order of imports (and explicitly putting hmac) as follows:

import hmac
import urllib3
import requests

results in the following error

pygame 2.1.4.dev1 (SDL 2.24.2, Python 3.11.1)
Hello from the pygame community. https://www.pygame.org/contribute.html
284: assets found : 0
341: EventTarget delayed by loader
/data/data/org.python/assets/site-packages/pygame/sysfont.py:235: UserWarning: no fc_cache font cache file at /data/data/src/assets/fc_cache
  warnings.warn(f"no fc_cache font cache file at {fc_cache}")
238: fc-cache: freesans {(True, False): '/data/data/org.python/assets/site-packages/pygame/freesansbold.ttf'}

        * Waiting for media user engagement : please click/touch page *
    
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1020: import scan filename='<stdin>' len(code)=2421 ['hmac', 'urllib3', 'requests']
1044: requesting module want='hmac' for file='<stdin>' 
1063: repo['-CDN-']='http://localhost:8030/archives/repo/' does not provide want='hmac'
1044: requesting module want='urllib3' for file='<stdin>' 
1055: module want='urllib3' requested
1044: requesting module want='requests' for file='<stdin>' 
1055: module want='requests' requested
1204: want='urllib3' found : True
pkg : http://localhost:8030/archives/repo/pkg/urllib3-2.0.2-py3-none-any.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
1204: want='requests' found : True
pkg : http://localhost:8030/archives/repo/pkg/requests-2.31.0-py3-none-any.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
646: starting shell
996: 90 lines queued for async eval
going interactive
643: TODO detect input/print to select repl debug
642: starting EventTarget in a few seconds

Python 3.11.1 (main, Jan  4 2023, 04:23:18) [Clang 16.0.0 (https://github.com/llvm/llvm-project 9ab0d4d66fa14a9c57864fea7259 on emscripten
Type "help", "copyright", "credits" or "license" for more information.
1204: want='hmac' found : False
PKG NOT FOUND : want='hmac', resume=<function <module> at 0xde8f40>, ex=ModuleNotFoundError("No module named 'hmac'")

@pmp-p
Copy link
Member

pmp-p commented Jun 11, 2023

Sorry requests is a synchronous module, at this time it will never work with pygbag ( only maybe later with pyodide when wasm will support js promises but that won't be until pygbag 2.x ).

Meanwhile either find an asynchronous implementation of requests, or write your own upon browser fetch api, as pyodide/pyscript has actually quite same behaviour you can look there to find guidance.

@andreagalle
Copy link
Author

Where can I look to find guidance?

What's the issue with synchronous modules in pygbag? Could you provide some hint to better investigate this issue please?

@pmp-p
Copy link
Member

pmp-p commented Jun 13, 2023

All files/network io and time.sleep are synchronous in standard python interpreter, but wasm engine don't allow for wasm programs to pause and resume when needed. To fix that is outside python/emscripten scope see https://webassembly.org/ instead.
Others ways to fix at user level like emscripten asyncify / webworkers or stackless pythons are still not acceptable for games.

eg pyscript/pyscript#324 pyodide/pyodide#398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants