LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-17-2011, 09:36 PM   #1
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Rep: Reputation: 45
Angry Different Versions of Python


Hi,

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

Script1
#!/bin/python

import Mytest

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

Mytest(list1, list2P


script 2 (MyTest)
#/usr/local/bin/python

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

The error message is :

NameError: global name 'set' is not defined



Thanks
Keith.
 
Old 04-17-2011, 10:16 PM   #2
jcomeau_ictx
LQ Newbie
 
Registered: Aug 2004
Location: Petaluma, CA, US
Distribution: Debian GNU/Linux squeeze/sid
Posts: 28

Rep: Reputation: 17
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.

Last edited by jcomeau_ictx; 04-17-2011 at 10:20 PM.
 
Old 04-19-2011, 01:20 AM   #3
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 45
Hey

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.
 
Old 04-19-2011, 01:56 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Maybe if you show us the offending line we can help more? Take out any sensitive info if it is an issue.
 
Old 04-19-2011, 07:50 PM   #5
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 45
Ok thanks

# Make Connection and Return the client and Session ID
def connection(host='myhost.com', 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"
to
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.
 
Old 04-19-2011, 08:46 PM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
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:
Code:
xmlrpclib.Server
What I get returned when searching the current version is found here.

Are you able to fill in the blanks for me?
 
Old 04-19-2011, 10:22 PM   #7
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 45
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.
 
Old 04-19-2011, 10:30 PM   #8
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
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.
 
Old 04-20-2011, 05:45 AM   #9
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 45
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 !

Keith
 
Old 04-20-2011, 06:26 AM   #10
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
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?
 
Old 04-20-2011, 06:33 AM   #11
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
Change it to:
Code:
#!/bin/python2.7
 
Old 04-20-2011, 06:54 AM   #12
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Well I do not think that will work too well seeing his 2.7 version is not installed under /bin.
 
Old 04-20-2011, 09:24 AM   #13
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
Quote:
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 xmlrpclib.py with text chopped out :
Code:
..
.. 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
    scheme://host/target.

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

    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 :
Code:
python2.7 -c "from httplib import HTTPS"
and check no error is reported.
 
Old 04-20-2011, 11:26 AM   #14
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Thanks bgeddy .. that makes more sense now

I also found a short example where a user simply had the following:
Code:
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?
 
Old 05-11-2011, 09:26 PM   #15
FragInHell
Member
 
Registered: Sep 2003
Location: Sydney Australia
Distribution: Redhat, Centos, Ubuntu
Posts: 282

Original Poster
Rep: Reputation: 45
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.

Keith.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Prepare firmware versions availability for current versions mufy AIX 2 01-03-2011 11:19 AM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 09:30 PM
install latest versions of python, pygtk and glib kosmognov Linux - Software 2 05-12-2006 03:30 PM
gcc versions compatibility with kernel versions.. mahesh_manthapuri Suse/Novell 1 03-22-2006 01:28 AM
different python versions on the same box birras Red Hat 0 11-14-2004 01:51 PM


All times are GMT -5. The time now is 09:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration