Broken ajax

22 views
Skip to first unread message

Edward Elliott

unread,
Mar 22, 2023, 1:12:43 PM3/22/23
to bry...@googlegroups.com
Something's broken with ajax module in Brython 3.11.0.  Importing ajax raises this error in console (chrome and safari):

Traceback (most recent call last):
  File "http://server.local:8001/results.py", line 13, in <module>
    from browser import ajax
ModuleNotFoundError: No module named 'browser.ajax'

Test code

<html>

<head>

    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bry...@3.11.0/brython.min.js">

    </script>

</head>


<body onload="brython()">


<script type="text/python">

import browser

from browser import ajax

</script>


</body>

</html>


Kiko

unread,
Mar 22, 2023, 2:40:41 PM3/22/23
to bry...@googlegroups.com
You have to load also the stdlib.

Have a look here:
https://www.brython.info/static_doc/en/install.html

Let us know if it solves the issue.

KR,

>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CAF1%3DpDkpZqSpd5jeHyGmd3JAKL0dJ%2B8PFJdOamUyGhM5Dck5Ww%40mail.gmail.com.
>

Edward Elliott

unread,
Mar 22, 2023, 5:59:43 PM3/22/23
to bry...@googlegroups.com
Thanks kiko.  That seemed to fix it.

It's very strange because I have an old project that doesn't use stdlib and ajax import works just fine.  Also, I thought any "from browser import X" items were part of the base distribution.  If it's in the stdlib why not just "import ajax" instead.  Oh well.




Kiko

unread,
Mar 23, 2023, 2:55:55 AM3/23/23
to bry...@googlegroups.com
2023-03-22 22:59 GMT+01:00, Edward Elliott <ese...@gmail.com>:
> Thanks kiko. That seemed to fix it.
>
> It's very strange because I have an old project that doesn't use stdlib and
> ajax import works just fine. Also, I thought any "from browser import X"
> items were part of the base distribution. If it's in the stdlib why not
> just "import ajax" instead. Oh well.

In the past there was a brython_dist.js
(https://www.jsdelivr.com/package/npm/brython?tab=files&version=3.2.6)
that merged brython+stdlib. Maybe you were using this.

The brython specific modules are included within browser and
javascript modules so ajax is included within browser. It is just an
implementation detail.
>> https://groups.google.com/d/msgid/brython/CAB-sx639ERCEKya5AFZ3W%3Duvgvonbm7-ZWP2iZ9bTD1BpHCeiA%40mail.gmail.com
>> .
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CAF1%3DpD%3DZ9Dv0oAjYMmvjQS-xXBByjXoBH9T__mO7PDXzZF9PpQ%40mail.gmail.com.
>

Edward Elliott

unread,
Mar 23, 2023, 11:46:41 AM3/23/23
to bry...@googlegroups.com
On Thu, Mar 23, 2023 at 6:55 AM Kiko <kikoco...@gmail.com> wrote:
In the past there was a brython_dist.js
(https://www.jsdelivr.com/package/npm/brython?tab=files&version=3.2.6)
that merged brython+stdlib. Maybe you were using this.

It's possible.  I haven't made a new brython project from scratch in years.  Just add to existing projects / environments.
The brython specific modules are included within browser and
javascript modules so ajax is included within browser. It is just an
implementation detail.
 
From an implementation standpoint, sure.  Any module can load from anywhere, doesn't matter.

From a user standpoint, importing ajax "from browser" makes it appear to be part of the base distribution.  You wouldn't put window or console or document in stdlib.  Those are basic features that every web app expects to be available at a minimum.  Same with ajax.  Very surprised that's not the case here.

Anyway it works, so thanks!

Reply all
Reply to author
Forward
0 new messages