-   Programming (
-   -   Different Versions of Python (

FragInHell 04-17-2011 08:36 PM

Different Versions of Python

I have a Red Hat 4.9 server running python 2.3.4. However I need some of the new functions so I downloaded and installed Python 2.7.1. I wanted to use the "set" function which was not in the earlier version.

/bin/python is 2.3.4
/usr/local/bin/python is 2.7.1

I have a script running 2.3.4
which calls the 2.7.1 script however it fails because it cannot find the "set" command

here is an example


import Mytest

list1 = ["1","2","3"]
list2 = ["3"]

Mytest(list1, list2P

script 2 (MyTest)

def MyTest(list1, list2)
diff = list(set(list1).difference(set(list2)))
return diff

The error message is :

NameError: global name 'set' is not defined


jcomeau_ictx 04-17-2011 09:16 PM

just change the first line from #!/bin/python of your first script to #!/usr/local/bin/python and you should be good to go. "import" won't get you the new interpreter.

2.7 should be fully backward compatible with earlier 2.x versions, so no reason not to run all your Python scripts with the new interpreter.

FragInHell 04-19-2011 12:20 AM


Thanks for getting back to me. When I changed all my script to Pyhton 2.7.1 I got the following error in my script

NotImplementedError: your version of httplib doesn't support HTTPS

The xmlrpc call works fine in 2.3.4 but not in 2.7.1

I can change the call to http but I would prefer to keep it https. I'm very new to python so any help or advice is most welcome.

Thanks again.

grail 04-19-2011 12:56 AM

Maybe if you show us the offending line we can help more? Take out any sensitive info if it is an issue.

FragInHell 04-19-2011 06:50 PM

Ok thanks

# Make Connection and Return the client and Session ID
def connection(host='', username='user', password='password' ):
host = "http://" + host + "/rpc/api"
client = xmlrpclib.Server(host)
session = client.auth.login(username, password)
return client, session

Here is the offending code.
If I change :
host = "https://" + host + "/rpc/api"
host = "http://" + host + "/rpc/api"
It works in 2.7.1

It will connect on http or https in 2.3.4 but only in http on 2.7.1. Its not really a drama however it would be nice to use the https as its available.

grail 04-19-2011 07:46 PM

hmmm ... I think I am still missing some information :(

I say this as I searched the docs for both versions and I am unable to find the following:

What I get returned when searching the current version is found here.

Are you able to fill in the blanks for me?

FragInHell 04-19-2011 09:22 PM

This script connects to Red Hat Satellite for some API reporting scripts that I'm trying to write.
I can make all the API calls etc, but since switching to 2.7.1 can no longer use the HTTPS.
I could try it on another system and see what happens.

grail 04-19-2011 09:30 PM

Yeah I am not so much concerned what you are trying to connect to, but more that I am unable to find the command listed in my previous post in either version of Python?
Is 'Server' an alias to another command? As I said inn previous post, that link I supplied is all I could find based on the line in your code.

FragInHell 04-20-2011 04:45 AM

Hi Grail,

I'm at my limit of Python knowledge so far ! I don't know if that xmlrpclib is custom or not hence the command is not found or possibly linked as you suggested.
would the output of python -v from both help ? (I'm guessing here)

Thanks for you help !


grail 04-20-2011 05:26 AM

From memory, have a look in your script for the import lines and try and find which relate to this module. Generally it will be near the top,
maybe you can just copy those in here and i can check out which one we need to look at?

X.Cyclop 04-20-2011 05:33 AM

Change it to:


grail 04-20-2011 05:54 AM

Well I do not think that will work too well seeing his 2.7 version is not installed under /bin.

bgeddy 04-20-2011 08:24 AM


Yeah I am not so much concerned what you are trying to connect to, but more that I am unable to find the command listed in my previous post in either version of Python?
Is 'Server' an alias to another command? As I said inn previous post, that link I supplied is all I could find based on the line in your code.
From python 2.64 standard library with text chopped out :

.. Text chopped out here
# Standard server proxy.  This class establishes a virtual connection
# to an XML-RPC server.
# <p>
# This class is available as ServerProxy and Server.  New code should
# use ServerProxy, to avoid confusion.
# @def ServerProxy(uri, **options)
# @param uri The connection point on the server.
# @keyparam transport A transport factory, compatible with the
#    standard transport class.
# @keyparam encoding The default encoding used for 8-bit strings
#    (default is UTF-8).
# @keyparam verbose Use a true value to enable debugging output.
#    (printed to standard output).
# @see Transport

class ServerProxy:
    """uri [,options] -> a logical connection to an XML-RPC server

    uri is the connection point on the server, given as

    The standard implementation always supports the "http" scheme.  If
    SSL socket support is available (Python 2.0), it also supports

    If the target part and the slash preceding it are both omitted,
    "/RPC2" is assumed.

    The following options can be given as keyword arguments:

        transport: a transport factory
        encoding: the request encoding (default is UTF-8)

    All 8-bit strings passed to the server proxy are assumed to use
    the given encoding.
.. Text chopped out here
Server = xmlrpclib.ServProxy

So Server is just bound to xmlrpclib.ServerProxy. I don't have python 2.7 to look into but it seems odd if support for https has been dropped out of xmlrpclib. It looks like there is something odd in your copy of httplib in the python2.7 standard library. You can check that support for HTTPS is there with this from the command line :

python2.7 -c "from httplib import HTTPS"
and check no error is reported.

grail 04-20-2011 10:26 AM

Thanks bgeddy .. that makes more sense now :)

I also found a short example where a user simply had the following:

import xmlrpclib
server_url = 'https://myserver'
server = xmlrpclib.Server(server_url);

Which he indicated worked just fine. So I know this is a silly question but you have tried the code in isolation and with the full url entered, as opposed to concatenating strings
passed into a function?

FragInHell 05-11-2011 08:26 PM

Hi Guys

Sorry for the delay.

Ok so I tested the suggestion of not using a string. I used an old script that had the server hardcoded etc. It works fine with 2.4 but when I switched to 2.7 same problem. As soon as I changed it to http rather than https all ok.
So interestingly I tired this on another system completely and it works fine. I think its something to do with the local configuration on this server. Its not worth any more effort at this stage, so I'm going to put it down to one of those gremlins !
Thanks for everyone's help and suggestions.


All times are GMT -5. The time now is 08:53 AM.