By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

Python and SSL enabled

P: n/a

I am have version 2.3.4. I want to write a python script to access a
secure HTTPS.

I tried the following:

import urllib
urllib.urlopen("https://somesecuresite.com")
s = f.read()
f.close()

I get the following:

IOError [Errno url error] unknown url type: 'https'

1. How do I know if SSL is enabled?
2. What can I do to get this to work?

Thanks,

Matey

Oct 24 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
matey wrote:
I am have version 2.3.4. I want to write a python script to access a
secure HTTPS.

I tried the following:

import urllib
urllib.urlopen("https://somesecuresite.com")
s = f.read()
f.close()
I hope you know the Python stdlib SSL does not provide certificate
checking etc. security features you almost certainly want in a
production application. There are several 3rd party Python crypto
libraries that provide more secure SSL out of the box, for example M2Crypto.

--
Heikki Toivonen
Oct 25 '06 #2

P: n/a
Problem: I want to be able to access an HTTPS website read/write
commands
to this website.
>From reading this group it appears I need M2Crypto and OpenSSL
Current version of Python 2.3.4

I downloaded:
M2Crypto 0.16
OpenSSL 0.9.7k
SWIG 1.3.29

Compiled OpenSSL libraries are located in /home/mmedina/lib/libcrypto.a
and libssl.a
I compiled M2Crytpo

cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/build/lib.solaris-2.9-sun4u-2.3/M2Crypto
>ls -alt
total 1624
drwxr-xr-x 4 mmedina asip 512 Oct 31 09:45 ./
-rwxr-xr-x 1 mmedina asip 690332 Oct 31 09:45 __m2crypto.so*
drwxr-xr-x 3 mmedina asip 512 Oct 30 08:38 ../
drwxr-xr-x 2 mmedina asip 512 Oct 30 08:38 PGP/
drwxr-xr-x 2 mmedina asip 512 Oct 30 08:38 SSL/
-rw-r--r-- 1 mmedina asip 8655 Jul 5 13:35 EC.py
-rw-r--r-- 1 mmedina asip 771 Jun 12 10:36 __init__.py
-rw-r--r-- 1 mmedina asip 14018 May 22 14:06 DSA.py
-rw-r--r-- 1 mmedina asip 1588 May 10 14:31 util.py
-rw-r--r-- 1 mmedina asip 7189 Apr 27 2006 SMIME.py
-rw-r--r-- 1 mmedina asip 2118 Apr 27 2006 m2urllib.py
-rw-r--r-- 1 mmedina asip 10784 Apr 26 2006 EVP.py
-rw-r--r-- 1 mmedina asip 11238 Apr 26 2006 RSA.py
-rw-r--r-- 1 mmedina asip 25817 Apr 11 2006 X509.py
-rw-r--r-- 1 mmedina asip 207 Mar 31 2006 callback.py
-rw-r--r-- 1 mmedina asip 379 Mar 29 2006 Rand.py
-rw-r--r-- 1 mmedina asip 7302 Mar 25 2006 BIO.py
-rw-r--r-- 1 mmedina asip 3306 Mar 20 2006 ASN1.py
-rw-r--r-- 1 mmedina asip 3085 Mar 20 2006 AuthCookie.py
-rw-r--r-- 1 mmedina asip 1330 Mar 20 2006 BN.py
-rw-r--r-- 1 mmedina asip 2374 Mar 20 2006 DH.py
-rw-r--r-- 1 mmedina asip 936 Mar 20 2006 Err.py
-rw-r--r-- 1 mmedina asip 692 Mar 20 2006 RC4.py
-rw-r--r-- 1 mmedina asip 2896 Mar 20 2006 ftpslib.py
-rw-r--r-- 1 mmedina asip 2210 Mar 20 2006 httpslib.py
-rw-r--r-- 1 mmedina asip 785 Mar 20 2006 m2.py
-rw-r--r-- 1 mmedina asip 1804 Mar 20 2006 m2xmlrpclib.py
-rw-r--r-- 1 mmedina asip 347 Mar 20 2006 threading.py
cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/build/lib.solaris-2.9-sun4u-2.3/M2Crypto
>
However, when I use the following command: python setup.py install
I get the following error:

creating /usr/local/lib/python2.3/site-packages/M2Crypto
error: could not create
'/usr/local/lib/python2.3/site-packages/M2Crypto': Permission denied

Since I don't have root privleges can I install the M2Crypto somewhere
else?

Also, am I on the right track if I want to be able to access an Https
page?

thanks in advance,

Monica
Heikki Toivonen wrote:
matey wrote:
I am have version 2.3.4. I want to write a python script to access a
secure HTTPS.

I tried the following:

import urllib
urllib.urlopen("https://somesecuresite.com")
s = f.read()
f.close()

I hope you know the Python stdlib SSL does not provide certificate
checking etc. security features you almost certainly want in a
production application. There are several 3rd party Python crypto
libraries that provide more secure SSL out of the box, for example M2Crypto.

--
Heikki Toivonen
Oct 31 '06 #3

P: n/a
matey wrote:
However, when I use the following command: python setup.py install
I get the following error:

creating /usr/local/lib/python2.3/site-packages/M2Crypto
error: could not create
'/usr/local/lib/python2.3/site-packages/M2Crypto': Permission denied
Ok, it looks like you M2Crypto built ok, but now you face this
permission problem which is not specific to M2Crypto. You'd run into
this with any 3rd party python module.
Since I don't have root privleges can I install the M2Crypto somewhere
else?
You could manually copy the built M2Crypto directory somewhere in your
home directory, for example:

/home/mmedina/python2.3/site-packages/M2Crypto

Then, you'd edit (or create) PYTHONPATH environment variable so that it
contained /home/mmedina/python2.3/site-packages. After that you should
be able to import M2Crypto in your scripts. In the future if you needed
more 3rd party libs you could just place them as siblings of M2Crypto in
your personal site-packages dir we created above.

An alternative is to copy M2Crypto and any other 3rd party libs into the
same dir where your python script is so that when you do an import, the
3rd party libs are found in the same dir.

--
Heikki Toivonen
Nov 1 '06 #4

P: n/a
Firstly, thank for answering. Otherwise I wouldn't know where to turn
for help.......
I tried to run the following simple program....

#!/usr/local/bin/python

import M2Crypto

u = M2Crypto.m2urllib.URLopener()
u.open('http://www.yahoo.com')

However I got the following errror:

Traceback (most recent call last):
File "test.py", line 3, in ?
import M2Crypto
File "/home/mmedina/python2.3/site-packages/M2Crypto/__init__.py",
line 14, in ?
import __m2crypto
ImportError: ld.so.1: python: fatal: relocation error: file
/home/mmedina/python2.3/site-packages/M2Crypto/__m2crypto.so: symbol
d2i_SSL_SESSION: referenced symbol not found
cengsu01:/home/mmedina/scripts/python >

However, I went back to INSTALL instructions for m2crytpo. I saw I
forgot to run alltests.py

I ran the alltests.py and received the following:

Traceback (most recent call last):
File "alltests.py", line 61, in ?
from M2Crypto import Rand
File
"/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/M2Crypto/__init__.py",
line 14, in ?
import __m2crypto
ImportError: No module named __m2crypto
cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/tests

Can you tell me what I did not do?

Thanks in advance.

Heikki Toivonen wrote:
matey wrote:
However, when I use the following command: python setup.py install
I get the following error:

creating /usr/local/lib/python2.3/site-packages/M2Crypto
error: could not create
'/usr/local/lib/python2.3/site-packages/M2Crypto': Permission denied

Ok, it looks like you M2Crypto built ok, but now you face this
permission problem which is not specific to M2Crypto. You'd run into
this with any 3rd party python module.
Since I don't have root privleges can I install the M2Crypto somewhere
else?

You could manually copy the built M2Crypto directory somewhere in your
home directory, for example:

/home/mmedina/python2.3/site-packages/M2Crypto

Then, you'd edit (or create) PYTHONPATH environment variable so that it
contained /home/mmedina/python2.3/site-packages. After that you should
be able to import M2Crypto in your scripts. In the future if you needed
more 3rd party libs you could just place them as siblings of M2Crypto in
your personal site-packages dir we created above.

An alternative is to copy M2Crypto and any other 3rd party libs into the
same dir where your python script is so that when you do an import, the
3rd party libs are found in the same dir.

--
Heikki Toivonen
Nov 1 '06 #5

P: n/a
matey wrote:
I tried to run the following simple program....

#!/usr/local/bin/python

import M2Crypto

u = M2Crypto.m2urllib.URLopener()
u.open('http://www.yahoo.com')

However I got the following errror:

Traceback (most recent call last):
File "test.py", line 3, in ?
import M2Crypto
File "/home/mmedina/python2.3/site-packages/M2Crypto/__init__.py",
line 14, in ?
import __m2crypto
ImportError: ld.so.1: python: fatal: relocation error: file
/home/mmedina/python2.3/site-packages/M2Crypto/__m2crypto.so: symbol
d2i_SSL_SESSION: referenced symbol not found
cengsu01:/home/mmedina/scripts/python >
Sorry, no idea why you are getting this.

Btw, I think even the M2Crypto m2urllib is unsafe, you'd be better of
using some of the other convenience libs libs httpslib or something.
However, I went back to INSTALL instructions for m2crytpo. I saw I
forgot to run alltests.py

I ran the alltests.py and received the following:

Traceback (most recent call last):
ImportError: No module named __m2crypto
Currently you need to install M2Crypto before you can run the tests.
Next version of M2Crypto will have an option to run tests without
installing. I'd assume if copied the sources to your own site-packages
dir and set the PYTHONPATH environment variable this would have worked.
Notice that you'd need to copy the *built* M2Crypto dir, not the source
M2Crypto dir which does not include the .so file.

--
Heikki Toivonen
Nov 2 '06 #6

P: n/a
It appears my __m2crypto.so didn't get built correctly.
================================================
cengsu01:/home/mmedina/crypt/m2kcrypto/m2crypto-0.16 >python setup.py
build
/usr/local/lib/python2.3/distutils/extension.py:128: UserWarning:
Unknown Extension options: 'swig_opts'
warnings.warn(msg)
running build
running build_py
running build_ext
building '__m2crypto' extension
swig -python -ISWIG -I/home/mmedina/crypt/openssl/openssl-0.9.8/include
-o SWIG/_m2crypto.c SWIG/_m2crypto.i
gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes
-fPIC -I/home/mmedina/crypt/m2kcrypto/m2crypto-0.16/SWIG
-I/home/mmedina/crypt/openssl/openssl-0.9.8/include
-I/usr/local/include/python2.3 -c SWIG/_m2crypto.c -o
build/temp.solaris-2.9-sun4u-2.3/SWIG/_m2crypto.o -DTHREADING
In file included from /usr/local/include/python2.3/stringobject.h:10,
from /usr/local/include/python2.3/Python.h:83,
from SWIG/_m2crypto.c:13:
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.9/2.95.3/include/stdarg.h:170:
warning: redefinition of `va_list'
/usr/include/stdio.h:120: warning: `va_list' previously declared here
SWIG/_m2crypto.c:3502: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:3666: warning: function declaration isn't a prototype
SWIG/_m2crypto.c: In function `make_stack_from_der_sequence':
SWIG/_m2crypto.c:3763: warning: function declaration isn't a prototype
SWIG/_m2crypto.c: At top level:
SWIG/_m2crypto.c:4897: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:5589: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:6556: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:7689: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:8111: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:8912: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:10924: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:13654: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:15281: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:13654: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:15281: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:15302: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:15895: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:16086: warning: function declaration isn't a prototype
SWIG/_m2crypto.c:559: warning: `SWIG_Python_ConvertPacked' defined but
not used
warning: no library file corresponding to '/home/mmedina/lib' found
(skipping)
gcc -shared build/temp.solaris-2.9-sun4u-2.3/SWIG/_m2crypto.o
-L/home/mmedina/crypt/openssl/openssl-0.9.8/lib -lssl -lcrypto -o
build/lib.solaris-2.9-sun4u-2.3/M2Crypto/__m2crypto.so
Text relocation remains referenced
against symbol offset in file
<unknown 0x5c0
/home/mmedina/lib/libssl.a(s3_lib.o)
<unknown 0x5c4
/home/mmedina/lib/libssl.a(s3_lib.o)
<unknown 0x5c8
/home/mmedina/lib/libssl.a(s3_lib.o)
<unknown 0x5cc /home/mmedina/li
================================================== ======

Not sure what is going on here. Can it not find my libraries?

Heikki Toivonen wrote:
matey wrote:
I tried to run the following simple program....

#!/usr/local/bin/python

import M2Crypto

u = M2Crypto.m2urllib.URLopener()
u.open('http://www.yahoo.com')

However I got the following errror:

Traceback (most recent call last):
File "test.py", line 3, in ?
import M2Crypto
File "/home/mmedina/python2.3/site-packages/M2Crypto/__init__.py",
line 14, in ?
import __m2crypto
ImportError: ld.so.1: python: fatal: relocation error: file
/home/mmedina/python2.3/site-packages/M2Crypto/__m2crypto.so: symbol
d2i_SSL_SESSION: referenced symbol not found
cengsu01:/home/mmedina/scripts/python >

Sorry, no idea why you are getting this.

Btw, I think even the M2Crypto m2urllib is unsafe, you'd be better of
using some of the other convenience libs libs httpslib or something.
However, I went back to INSTALL instructions for m2crytpo. I saw I
forgot to run alltests.py

I ran the alltests.py and received the following:

Traceback (most recent call last):
ImportError: No module named __m2crypto

Currently you need to install M2Crypto before you can run the tests.
Next version of M2Crypto will have an option to run tests without
installing. I'd assume if copied the sources to your own site-packages
dir and set the PYTHONPATH environment variable this would have worked.
Notice that you'd need to copy the *built* M2Crypto dir, not the source
M2Crypto dir which does not include the .so file.

--
Heikki Toivonen
Nov 3 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.