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. |
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. |
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. |
Maybe if you show us the offending line we can help more? Take out any sensitive info if it is an issue.
|
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. |
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 Are you able to fill in the blanks for me? |
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. |
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. |
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 |
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? |
Change it to:
Code:
#!/bin/python2.7 |
Well I do not think that will work too well seeing his 2.7 version is not installed under /bin.
|
Quote:
Code:
.. Code:
python2.7 -c "from httplib import HTTPS" |
Thanks bgeddy .. that makes more sense now :)
I also found a short example where a user simply had the following: Code:
import xmlrpclib passed into a function? |
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. |
All times are GMT -5. The time now is 10:52 PM. |