-2

I'm trying to make a simple Hello World web page in Python 3.7.4 and web.py 0.40-dev1 (which is supposed to be compatible) and I'm running into

AttributeError: module 'web' has no attribute 'applications'

error. I've googled enough to know that is a name collision, but for the love of God I can't trace it.

Here's the full code:

import web

urls = (
    '/', 'index'
)

application = web.applications(urls, globals())

class index:
    def GET(self):
        greeting = 'Hello world'
        return greeting

if __name__ == "__main__":
    application.run

And here's the full Python interpreter output:

Traceback (most recent call last):
  File "bin\app.py", line 7, in <module>
    application = web.applications(urls, globals())
AttributeError: module 'web' has no attribute 'applications'
ADSMarko
  • 363
  • 1
  • 3
  • 8

2 Answers2

1

Just took a quick look at the docs. It looks like the command you are looking for is web.application not web.applications. Note the absence of the s on applications.

Robert Kearns
  • 1,631
  • 1
  • 8
  • 15
  • OP has a variable with the same name. although it will not collide in this case, it can lead to confusion. – Skaperen Aug 04 '19 at 04:57
  • It could potentially lead to some confusion. But he has not done a wild card import ```from web import *```, so the ```web``` prefix is always required. Personally this would avoid any confusion for me. – Robert Kearns Aug 04 '19 at 05:00
  • Yep, that solved that issue. Now I'm getting ‚RuntimeError: generator raised StopIteration‚ from \web\utils.py. I guess I should ask that that question. – ADSMarko Aug 04 '19 at 05:12
  • post a new question after you google the new problem. – Skaperen Aug 04 '19 at 05:39
1

Because of you I just install web.py to test your code. It seems there is no applications in the web.py. If your want to check it just try the below example.

>>> import web
>>> 
>>> `applications` in dir(web)
False
>>> `application` in dir(web)
True

So is should be web.application. Your first problem be solved, when you run it you'll get another error RuntimeError: generator raised StopIteration. That problem is solved in “RuntimeError: generator raised StopIteration” every time I try to run app question. It occurs because of python 3.7.* versions. There is something wrong with 0.40-dev1 version. You have two opetions.

  1. Remove the 0.40-dev1 version and install the stable version from there master branch. Just uninstall by using this command pip uninstall web.py==0.40-dev1 and run this command pip install -e git+https://github.com/webpy/webpy.git#egg=webpy. This will install the latest version from master branch. (This is worked for me)
  2. Next one is update the utils.py in this way. Find it from from Python\Python37\Lib\site-packages\web\utils.py (I try it from windows) and find the line 526. Then you'll see something like thisyield next(seq) and surround it with try-catch statement in this way. (Not Recommended, instead of that make your own version by fork the relevant branch)
def take(seq, n):
    for i in range(n):
        # yield next(seq)
        try:
            yield next(seq)
        except StopIteration:
            return

This will solved your problem. I added some extra context here because I want to see the output. I don't know much about this change, just took it from “RuntimeError: generator raised StopIteration” every time I try to run app question.

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
  • 1
    If you need I can make a pull request to them (or you can do the same if you know about it). Then you can install your own version of `web.py` without change the file from `site-package`. – Kushan Gunasekera Aug 04 '19 at 05:21
  • did you mean to use back-ticks in your first example? – Skaperen Aug 04 '19 at 05:36
  • Sorry, I didn't get what you mentioned about `back-ticks` and the `first example`? Did you edit `utils.py` with my suggestions? – Kushan Gunasekera Aug 04 '19 at 05:38
  • @Kushan Gunasekera, I'm getting the same result. `0.40-dev1` and `0.40-dev0` raise same `RuntimeError: generator raised StopIteration` error at the same place and `0.39` is incompatible with Python 3.7. Admittedly I'm uncomfortable getting involved with third party project on github considering I just started learning Python the other day. – ADSMarko Aug 04 '19 at 05:44
  • No just wait @ADSMarko, I'll give you a solution, don't worry. Give me few minutes. Are you `windows` or `linux` user? – Kushan Gunasekera Aug 04 '19 at 05:45
  • @Kushan Gunasekera, Windows 10 (if it makes any difference). – ADSMarko Aug 04 '19 at 05:52
  • @ADSMarko same here, `Windows 10` with `Python 3.7.3`. I updated my answer and check the 1st solution or follow this. Please uninstall the current `web.py` version by running `pip uninstall web.py==0.40-dev1`. Then run this `pip install -e git+https://github.com/webpy/webpy.git#egg=webpy` command, that's it. Try it and let me know. – Kushan Gunasekera Aug 04 '19 at 05:54
  • @Kushan Gunasekera, good news now Python gives no error message (actually no output at all), bad news now localhost:8080 gives `This site can’t be reached`. What parameters should I pass to Python interpreter? – ADSMarko Aug 04 '19 at 06:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197441/discussion-between-kushan-gunasekera-and-adsmarko). – Kushan Gunasekera Aug 04 '19 at 06:59