SSL Error with Sparkpost api with web2py.exe

58 views
Skip to first unread message

icodk

unread,
Jun 9, 2017, 3:48:55 AM6/9/17
to web2py-users
Sparkpost has simple python api:
from sparkpost import SparkPost
sp
= SparkPost('YOUR API KEY')
response = sp.transmissions.send(
   
use_sandbox=True,
   
recipients=['som...@somedomain.com'],
   
html='<p>Hello world</p>',
   
from_email='te...@sparkpostbox.com',
   
subject='Hello from python-sparkpost'
)

print(response)

However I get the following error:
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

Could be something with the python version  in web2py.exe (I am useing  web2py_2_14_06)
Any idea

Massimo Di Pierro

unread,
Jun 11, 2017, 4:08:58 AM6/11/17
to web2py-users
First of all I recommend you configure sparkpost using web2py auth.mailer SMTP else you do not get the benefit of auth email logic.

Also, I recommend you run web2py from source, not the windows binary. I will give you more control. If you find that running from source makes the problem go away, please let us know.

Massimo


On Friday, 9 June 2017 02:48:55 UTC-5, icodk wrote:
Sparkpost has simple python api:
from sparkpost import SparkPost
sp
= SparkPost('YOUR API KEY')
response = sp.transmissions.send(
   
use_sandbox=True,
   
recipients=['someone@somedomain.com'],

   
html='<p>Hello world</p>',

   
from_email='test@sparkpostbox.com',

   
subject='Hello from python-sparkpost'
)

print(response)

However I get the following error:

icodk

unread,
Jun 15, 2017, 1:32:22 PM6/15/17
to web2py-users
Sorry for the late response
There is definitly a different if I use web2py  shell source  to send mail or web2py.exe
It works fine with source and failes with web2py.exe
My python installation is 2.7.13
here is my source execution :
C:\Temp\web2py_src\web2py>python web2py.py -S welcome
No handlers could be found for logger "web2py"
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2017
Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
Database drivers available: psycopg2, pymysql, imaplib, sqlite3, pg8000, pyodbc
WARNING:web2py:import IPython error; use default python shell
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> variables= {}
>>> execfile( "/temp/mailtest.py", variables )
{u'total_accepted_recipients': 1, u'id': u'48590550571575300', u'total_rejected_recipients': 0}
>>>

and here is with web2py.exe
Enter code here...>>> variables= {}
>>> execfile( "/temp/mailtest.py", variables )
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/temp/mailtest.py", line 10, in <module>
    subject='Hello from python-sparkpost'
  File "C:\Python27\lib\site-packages\sparkpost\transmissions.py", line 254, in send
    results = self.request('POST', self.uri, data=json.dumps(payload))
  File "C:\Python27\lib\site-packages\sparkpost\base.py", line 41, in request
    **kwargs)
  File "C:\Python27\lib\site-packages\sparkpost\base.py", line 12, in request
    response = self.sess.request(method, uri, headers=headers, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 623, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
>>>


On Sunday, June 11, 2017 at 10:08:58 AM UTC+2, Massimo Di Pierro wrote:
First of all I recommend you configure sparkpost using web2py auth.mailer SMTP else you do not get the benefit of auth email logic.

Also, I recommend you run web2py from source, not the windows binary. I will give you more control. If you find that running from source makes the problem go away, please let us know.

Massimo

On Friday, 9 June 2017 02:48:55 UTC-5, icodk wrote:
Sparkpost has simple python api:
from sparkpost import SparkPost
sp
= SparkPost('YOUR API KEY')
response = sp.transmissions.send(
   
use_sandbox=True,
   
recipients=['som...@somedomain.com'],

   
html='<p>Hello world</p>',

   
from_email='te...@sparkpostbox.com',

   
subject='Hello from python-sparkpost'
)

print(response)

However I get the following error:

icodk

unread,
Jun 15, 2017, 1:36:08 PM6/15/17
to web2py-users
With web2py.exe more complete screenshot
C:\Dev\web\web2py_win\web2py_2_14_06>web2py.exe -S welcome
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2017
Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
Database drivers available: psycopg2, pymysql, imaplib, MySQLdb, sqlite3, pyodbc
WARNING:web2py:import IPython error; use default python shell
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> execfile( "/temp/mailtest.py", variables )
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'variables' is not defined
>>> variables= {}
>>> execfile( "/temp/mailtest.py", variables )
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/temp/mailtest.py", line 10, in <module>
    subject='Hello from python-sparkpost'
  File "C:\Python27\lib\site-packages\sparkpost\transmissions.py", line 254, in send
    results = self.request('POST', self.uri, data=json.dumps(payload))
  File "C:\Python27\lib\site-packages\sparkpost\base.py", line 41, in request
    **kwargs)
  File "C:\Python27\lib\site-packages\sparkpost\base.py", line 12, in request
    response = self.sess.request(method, uri, headers=headers, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 513, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 623, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
>>>

On Friday, June 9, 2017 at 9:48:55 AM UTC+2, icodk wrote:
Sparkpost has simple python api:
from sparkpost import SparkPost
sp
= SparkPost('YOUR API KEY')
response = sp.transmissions.send(
   
use_sandbox=True,
   
recipients=['someone@somedomain.com'],

   
html='<p>Hello world</p>',

   
from_email='test@sparkpostbox.com',

   
subject='Hello from python-sparkpost'
)

print(response)

However I get the following error:

Dave S

unread,
Jun 16, 2017, 9:52:24 PM6/16/17
to web2py-users


On Thursday, June 15, 2017 at 10:32:22 AM UTC-7, icodk wrote:
Sorry for the late response
There is definitly a different if I use web2py  shell source  to send mail or web2py.exe
It works fine with source and failes with web2py.exe
My python installation is 2.7.13


As Massimo said, if you use web2py.exe you are not using your Python installation.

If you use the source version of web2py, you will not get web2py.exe with its built-in Python, you will get web2py.py and can invoke that (say, from the cmd prompt) with your Python.

python web2py.py -i 0.0.0.0 -p 8000


here is my source execution :
C:\Temp\web2py_src\web2py>python web2py.py -S welcome
No handlers could be found for logger "web2py"
web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2017
Version 2.14.6-stable+timestamp.2016.05.10.00.21.47
Database drivers available: psycopg2, pymysql, imaplib, sqlite3, pg8000, pyodbc
WARNING:web2py:import IPython error; use default python shell
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32

See?

 

No reference to your python installation there.

/dps
 
Reply all
Reply to author
Forward
0 new messages