cancel
Showing results for 
Search instead for 
Did you mean: 

Has Python support just been broken on the CGI server?

kdl
Dabbler
Posts: 13
Registered: ‎11-09-2008

Has Python support just been broken on the CGI server?

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.
2 REPLIES 2
bobpullen
Community Gaffer
Community Gaffer
Posts: 14,877
Thanks: 2,478
Fixes: 168
Registered: ‎04-04-2007

Re: Has Python support just been broken on the CGI server?

Not really my forté but I have a script uploaded to my CGI space to output the Python version:
#!/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 Huh

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵

kdl
Dabbler
Posts: 13
Registered: ‎11-09-2008

Re: Has Python support just been broken on the CGI server?

Hi Bob,
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 Huh

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 Cheesy ) ...
Thanks!