473,385 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Python and SSL enabled


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
6 3944
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
3
by: Alexander Fillips | last post by:
Hi, my short question: is there a python object which can interpret java-script? the whole story ;-) I wrote some streaming-scripts for the xbox mediaplayer which supports python. for a...
2
by: Frank Millman | last post by:
Hi all I need to pass data between a server program and a client program, both written in Python. My first thought was to use xml. The server builds up an xml string, without using any xml...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
6
by: Tool69 | last post by:
Hi, I saw several old posts speaking of vim scripting in Python. This one in particular : http://www.velocityreviews.com/forums/t351303-re-pythonising-the-vim-eg-syntax-popups-gt-vimpst.html ...
4
by: Phoe6 | last post by:
Hi all, I am trying to disable the NIC card (and other cards) enabled in my machine to test diagnostics on that card. I am trying to disable it programmatic using python. I checked python wmi and...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
0
by: Murat Gunduz | last post by:
Dear list member, I am using a Linux machine (Fedora Core 7, 64 bit): Linux 2.6.21-1.3228.fc7 #1 SMP Tue Jun 12 14:56:37 EDT 2007 x86_64 I tried to compile a software (ncvtk) with the simple...
3
by: Daniel Fetchinson | last post by:
Does Python 2.5.2's embedded SQLite support full text searching? Sqlite itself is not distributed with python. Only a python db api compliant wrapper is part of the python stdlib and as such it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.