Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Has Python support just been broken on the CGI server?
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Re: Has Python support just been broken on the CGI...
Has Python support just been broken on the CGI server?
09-08-2015 10:58 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi. I have a small system written in Python that I use my CGI space for.
I notice tonight that it has been broken in a way that seems to indicate some sort of invalid Python installation on the CGI server. My script, when attempting to import the 'cgi' module throws the following exception:
"""
Traceback (most recent call last):
File "/services/webpages/util/path/to/my/script.py", line 13, in <module>
import cgi
File "/usr/lib64/python2.6/cgi.py", line 40, in <module>
import urllib
File "/usr/lib64/python2.6/urllib.py", line 30, in <module>
from urlparse import urljoin as basejoin
File "/usr/lib64/python2.6/urlparse.py", line 108, in <module>
from collections import namedtuple
File "/usr/lib64/python2.6/collections.py", line 12, in <module>
from itertools import imap as _imap
ImportError: cannot import name imap
"""
So, this is something deep down in the Python standard library that can't find the built-in itertools.imap function.
Off the top of my head (I've only just noticed it so have not investigated further yet), it could be that Python 3.x has now been installed and is being used to run my script (which in itself will cause me no end of problems). However, if that was the case, why is it looking in the python2.6 library directory? I'm confused.
Any suggestions appreciated.
Kevin.
I notice tonight that it has been broken in a way that seems to indicate some sort of invalid Python installation on the CGI server. My script, when attempting to import the 'cgi' module throws the following exception:
"""
Traceback (most recent call last):
File "/services/webpages/util/path/to/my/script.py", line 13, in <module>
import cgi
File "/usr/lib64/python2.6/cgi.py", line 40, in <module>
import urllib
File "/usr/lib64/python2.6/urllib.py", line 30, in <module>
from urlparse import urljoin as basejoin
File "/usr/lib64/python2.6/urlparse.py", line 108, in <module>
from collections import namedtuple
File "/usr/lib64/python2.6/collections.py", line 12, in <module>
from itertools import imap as _imap
ImportError: cannot import name imap
"""
So, this is something deep down in the Python standard library that can't find the built-in itertools.imap function.
Off the top of my head (I've only just noticed it so have not investigated further yet), it could be that Python 3.x has now been installed and is being used to run my script (which in itself will cause me no end of problems). However, if that was the case, why is it looking in the python2.6 library directory? I'm confused.
Any suggestions appreciated.
Kevin.
Message 1 of 3
(1,348 Views)
2 REPLIES 2
Re: Has Python support just been broken on the CGI server?
11-08-2015 5:32 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Not really my forté but I have a script uploaded to my CGI space to output the Python version:
In case it's of any interest it outputs this:
[quote author="Hostopia's web servers"]2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
Anyway, if I add 'from itertools import imap as _imap' to my script and try and call it in a web browser, it doesn't throw an exception
#!/usr/bin/python
import sys
import cgi
import cgitb; cgitb.enable()
print "Content-type:text/html\r\n\r\n"
print sys.version
In case it's of any interest it outputs this:
[quote author="Hostopia's web servers"]2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
Anyway, if I add 'from itertools import imap as _imap' to my script and try and call it in a web browser, it doesn't throw an exception

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵
Message 2 of 3
(422 Views)
Re: Has Python support just been broken on the CGI server?
11-08-2015 9:55 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hi Bob,
Anyway, if I add 'from itertools import imap as _imap' to my script and try and call it in a web browser, it doesn't throw an exception
Thanks for checking this - what you said just rang a bell or two with me and yes, it's specific to my setup. I could have investigated this some more before I posted, but I wanted to quickly poll others to see if it was a general/known problem or not (nobody else said "works for me", so perhaps nobody else has Python CGI scripts ...).
[SOLVED] In the interests of anyone finding this thread from a search and wondering if it's relevant to an issue they are having:
Unfortunately, when the switch to Hostopia was made, we went backwards from the Python 2.3 (or later) that was on the old platform to 2.2. This removed a few features I was using, including the built-in itertools module. Rather than re-working my whole system to not use itertools, I quickly worked around this by writing my own local itertools module in Python containing just the functions my main scripts needed. As a real itertools module didn't exist, nothing in the standard library tried to import it.
It looks like the servers have now been upgraded to 2.6 (for which I'm actually very grateful, despite the sudden unexpected downtime) and so parts of the standard library _do_ expect the real itertools module and therefore some additional functions that I didn't implement in my workaround version. My local version overrides the built-in when imported, hence those functions are not available.
That's what the problem is. So, I can just delete my workaround module (or perhaps make it dynamic based on the Python version just in case it unexpectedly reverts to 2.2 again
) ...
Thanks!
Quote from: Bob In case it's of any interest it outputs this:
[quote author="Hostopia's web servers"]2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
Anyway, if I add 'from itertools import imap as _imap' to my script and try and call it in a web browser, it doesn't throw an exception

Thanks for checking this - what you said just rang a bell or two with me and yes, it's specific to my setup. I could have investigated this some more before I posted, but I wanted to quickly poll others to see if it was a general/known problem or not (nobody else said "works for me", so perhaps nobody else has Python CGI scripts ...).
[SOLVED] In the interests of anyone finding this thread from a search and wondering if it's relevant to an issue they are having:
Unfortunately, when the switch to Hostopia was made, we went backwards from the Python 2.3 (or later) that was on the old platform to 2.2. This removed a few features I was using, including the built-in itertools module. Rather than re-working my whole system to not use itertools, I quickly worked around this by writing my own local itertools module in Python containing just the functions my main scripts needed. As a real itertools module didn't exist, nothing in the standard library tried to import it.
It looks like the servers have now been upgraded to 2.6 (for which I'm actually very grateful, despite the sudden unexpected downtime) and so parts of the standard library _do_ expect the real itertools module and therefore some additional functions that I didn't implement in my workaround version. My local version overrides the built-in when imported, hence those functions are not available.
That's what the problem is. So, I can just delete my workaround module (or perhaps make it dynamic based on the Python version just in case it unexpectedly reverts to 2.2 again

Thanks!
Message 3 of 3
(422 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Re: Has Python support just been broken on the CGI...