The 'module' object does not have the 'FieldStorage' attribute

It makes no sense to me, because the code is very simple, and the documentation has "FieldStorage".

#!/usr/bin/env python
print 'Content-type: text/html'
print
import cgi

def Main():
    form = cgi.FieldStorage()
    print '<html>'
    print '<body>'
    print 'ola'
    print '</body>'
    print '</html>'

if __name__ == '__main__':
    Main()
+3
source share
2 answers

Do you have a local file with a name cgi.py? This is imported instead of the standard library module.

+12
source

I also had a problem with a file called io.py. This suggests that there are other standard module names that should be avoided when specifying your own .py files. As soon as I changed the file (and got rid of the cached io.pyc file, which was generated at an earlier start), the code behaved more normally.

0
source

Source: https://habr.com/ru/post/1774076/


All Articles