I have a simple code running good using http (not secure) but then I update it to https a get an error about ssl.SSLCertVerificationError
I'm using a heroku server with a valid ssl of course, python 3.7.3 on a mac, ssl.OPENSSL_VERSION= 1.1.0, certifi=2019.3.9, Flask=1.0.2, Flask-SocketIO=3.3.2
Here is the code:
import socketio
sio = socketio.Client()
#sio.on('connect')
def on_connect():
print('Connected ...')
#sio.on('message')
def on_message(data):
print('I received a message!')
print(data)
if __name__ == '__main__':
sio.connect('https://heroku.server.url')
And this is what I get using https:
Traceback (most recent call last):
File "/Users/calavraian/Devel/Projects/FlaskTesting/Client.py", line 21, in <module>
sio.connect('https://heroku.server.url')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/socketio/client.py", line 208, in connect
engineio_path=socketio_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 166, in connect
url, headers, engineio_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 303, in _connect_polling
if self._connect_websocket(url, headers, engineio_path):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/engineio/client.py", line 341, in _connect_websocket
cookie=cookies)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_core.py", line 514, in create_connection
websock.connect(url, **options)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_core.py", line 223, in connect
options.pop('socket', None))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 126, in connect
sock = _ssl_socket(sock, options.sslopt, hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 260, in _ssl_socket
sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websocket/_http.py", line 239, in _wrap_sni_socket
server_hostname=hostname,
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
Any ideas ?
Finally I made it work, I tried the same code on another Mac computer with the same software condition and it works fine, also on a PC with Ubuntu and a Raspberry Pi with Raspbian, everything works fine, so back again on the first Mac with the problem, I started to debug again, reinstalling and updating packages with pip and nothing happened.
Other solution that I have tried was to reinstall the certifi package with pip but nothing was fixed.
At the end, what solved the problem was running the script that comes with Python and is located in /Applications/Python 3.X/Install Certificates.command, you can run it directly from Finder with double clic on it or on a terminal go to the folder and execute it.
After doing this I tested python-socketio 3.1.2 and python-socketio 4.0.1 and everything works fine.
A final recommendation, in case that you are still getting the same error after try running the script, you can try an alternative to python-socketio, in the process to figure it out I have tried socketIO-client-2 when I was getting the error and this library worked good on the initial conditions (before running the script). After running the script above both are running perfect now.
Related
I have a script on python3.4 and it has been fine until the website I download the file from decides to use https and now I am getting error but can't figure out how I can retrive the file.
My script import the following library and uses the urlretrive to get the file previously. Since it is now forwarded to https with 302 redirection. I am getting some error.
import urllib
import urllib.request
urllib.request.urlretrieve("http://wordpress.org/latest.tar.gz", "/thefile.gz")
My error:-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/urllib/request.py", line 178, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/local/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.4/urllib/request.py", line 461, in open
response = meth(req, response)
File "/usr/local/lib/python3.4/urllib/request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python3.4/urllib/request.py", line 493, in error
result = self._call_chain(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 676, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/local/lib/python3.4/urllib/request.py", line 455, in open
response = self._open(req, data)
File "/usr/local/lib/python3.4/urllib/request.py", line 478, in _open
'unknown_open', req)
File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 1257, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>
Most likely your Python installation or operating system is broken.
Python has only support for HTTPS if it was compiled with HTTPS support. However, this should be the default for all sane installations.
HTTPS support is only available if the socket module was compiled with SSL support.
https://docs.python.org/3/library/http.client.html
Please clarify how you installed Python. Official Python distributions are available at python.org
I had the same problem with Anaconda but after installing the OpenSSL package, it works well.
conda install -c anaconda openssl
I ran into the similar problem.
I used anaconda, and I simply moved these two file to anaconda3\DLLs and it worked.
libcrypto-1_1-x64.dll
libssl-1_1-x64.dll
I don't know why.
The reason I know this is that I tried to use ssl module to ignore certificate errors.
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
After these lines, the https error went away and gave me another error:
DLL load failed while importing _ssl: The specified module could not be found.
So I went to this post and found these two important files.
ps: the ssl module is not necessary.
Had this issue, and it was solved by upgrading Python with
brew upgrade python
For me the error was resolved by downloading the correct version of openssl.
I was using python 3.7.5 32 bit version on windows 10 machine.
goto
https://slproweb.com/products/Win32OpenSSL.html and download Win32 OpenSSL v1.1.1h
EXE | MSI 54MB Installer version . I used 32 bit as my python interpreter was 32 bit.
Install and run.
Issue fixed :)
for HTTP
people who encountered the error
ValueError: unknown url type: 'http
or
ValueError: unknown url type: b'http
while opening some url like below with urllib.request.Request
'http://localhost/simple_form/insert.php'
just change localhost to 127.0.0.1
looks like Request method is looking for a domain.something in url
If your url has single or double quotes, i.e. '' or "", then it also gives this error.
Replace your single or double quotes with %20
url='http://stackoverflow.com/wizard.php?id="hah"'
should be changed to
url='http://stackoverflow.com/wizard.php?id=%20hah%20'
I'm using the Wordpress xmlrpc Python module on Python 3.6 to automatically write and publish blog posts to my Wordpress site (hosted directly by Wordpress).
The program runs great on one of my Windows machines, but when I try to run it using my second Windows machine, with the exact same code, on the same network, I receive an SSL error. Details below:
import ssl
import wordpress_xmlrpc
from wordpress_xmlrpc import Client
from wordpress_xmlrpc import WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts
from wordpress_xmlrpc.methods.posts import NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc.compat import xmlrpc_client
wp = Client("https://website.io/xmlrpc.php", "wordpressusername", "wordpresspassword")
post = WordPressPost()
post.title = "title"
post.content = content
post.post_status = 'publish'
status_draft = 0
status_published = 1
wp.call(NewPost(post))
Here's the error:
File "C:\Python36\Lib\http\client.py", line 964, in send
self.connect()
File "C:\Python36\Lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\Python36\Lib\ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:\Python36\Lib\ssl.py", line 808, in __init__
self.do_handshake()
File "C:\Python36\Lib\ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:\Python36\Lib\ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)
I've used pip list to view all installed modules on both machines and everything matches exactly. The code is stored on a synced Google Drive folder, so it's literally the exact same .py file both times. I can't understand why it works on one machine but not the other.
I've read the thread here but I don't believe it applies to the wordpress xmlrpc tool. I've read through the documentation here but I can't see anything helpful.
Is this something I have to tweak/delete/refresh the ssl certificates in Chrome or something? Any answers or insight much appreciated. Thanks in advance
So, 3 weeks later, I finally found a way to fix this.
I ended up completely uninstalling/deleting Python on my secondary machine and reinstalling everything (along with reinstalling all modules, and confirming via pip list) and now it works (no more SSL error).
For what it's worth, and I can't be sure this is what was causing the issue in the first place, but previously, I was running Python 3.6.1 on the working machine and python 3.6.2 on the other, non-working machine.
When I reinstalled everything, I reinstalled Python 3.6.1 (to match the working machine) and it worked on both.
I have a script on python3.4 and it has been fine until the website I download the file from decides to use https and now I am getting error but can't figure out how I can retrive the file.
My script import the following library and uses the urlretrive to get the file previously. Since it is now forwarded to https with 302 redirection. I am getting some error.
import urllib
import urllib.request
urllib.request.urlretrieve("http://wordpress.org/latest.tar.gz", "/thefile.gz")
My error:-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/urllib/request.py", line 178, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/local/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.4/urllib/request.py", line 461, in open
response = meth(req, response)
File "/usr/local/lib/python3.4/urllib/request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python3.4/urllib/request.py", line 493, in error
result = self._call_chain(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 676, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/local/lib/python3.4/urllib/request.py", line 455, in open
response = self._open(req, data)
File "/usr/local/lib/python3.4/urllib/request.py", line 478, in _open
'unknown_open', req)
File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.4/urllib/request.py", line 1257, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>
Most likely your Python installation or operating system is broken.
Python has only support for HTTPS if it was compiled with HTTPS support. However, this should be the default for all sane installations.
HTTPS support is only available if the socket module was compiled with SSL support.
https://docs.python.org/3/library/http.client.html
Please clarify how you installed Python. Official Python distributions are available at python.org
I had the same problem with Anaconda but after installing the OpenSSL package, it works well.
conda install -c anaconda openssl
I ran into the similar problem.
I used anaconda, and I simply moved these two file to anaconda3\DLLs and it worked.
libcrypto-1_1-x64.dll
libssl-1_1-x64.dll
I don't know why.
The reason I know this is that I tried to use ssl module to ignore certificate errors.
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
After these lines, the https error went away and gave me another error:
DLL load failed while importing _ssl: The specified module could not be found.
So I went to this post and found these two important files.
ps: the ssl module is not necessary.
Had this issue, and it was solved by upgrading Python with
brew upgrade python
For me the error was resolved by downloading the correct version of openssl.
I was using python 3.7.5 32 bit version on windows 10 machine.
goto
https://slproweb.com/products/Win32OpenSSL.html and download Win32 OpenSSL v1.1.1h
EXE | MSI 54MB Installer version . I used 32 bit as my python interpreter was 32 bit.
Install and run.
Issue fixed :)
for HTTP
people who encountered the error
ValueError: unknown url type: 'http
or
ValueError: unknown url type: b'http
while opening some url like below with urllib.request.Request
'http://localhost/simple_form/insert.php'
just change localhost to 127.0.0.1
looks like Request method is looking for a domain.something in url
If your url has single or double quotes, i.e. '' or "", then it also gives this error.
Replace your single or double quotes with %20
url='http://stackoverflow.com/wizard.php?id="hah"'
should be changed to
url='http://stackoverflow.com/wizard.php?id=%20hah%20'
I am using SSL Connection from Web Client (firefox) to connect to the local Server created via the code available in this link MDM server code I have all the required signed Certificates issued by Apple available for running the server, as well as all the depended python modules installed.
I ran my code using the following command on my Windows Machine.
python server.py .
This successfully start running the server at the port 8080.
C:\Users\Administrator\Desktop\MDMServer>python server.py <ip address>
Can't find MyApp.mobileprovision in current directory.
Need both MyApp.ipa and Manifest.plist to enable InstallCustomApp.
Starting Server
https://<ipaddress>:8080/
But whenever a Web Client tries to connect to this Server.
Upon launching the link https://<ip address>:8080 in the firefox. The Server reports the following error.
Traceback (most recent call last):
File "server.py", line 498, in <module>
app.run()
File "C:\Python27\lib\site-packages\web\application.py", line 313, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "C:\Python27\lib\site-packages\web\wsgi.py", line 54, in runwsgi
return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
File "C:\Python27\lib\site-packages\web\httpserver.py", line 157, in runsimple
server.start()
File "C:\Python27\lib\site-packages\web\wsgiserver\__init__.py", line 1765, in
start
self.tick()
File "C:\Python27\lib\site-packages\web\wsgiserver\__init__.py", line 1815, in
tick
s, ssl_env = self.ssl_adapter.wrap(s)
File "C:\Python27\lib\site-packages\web\wsgiserver\ssl_builtin.py", line 42, i
n wrap
keyfile=self.private_key, ssl_version=ssl.PROTOCOL_SSLv23)
File "C:\Python27\lib\ssl.py", line 372, in wrap_socket
ciphers=ciphers)
File "C:\Python27\lib\ssl.py", line 134, in __init__
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 296, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:503: error:1408A0C1:SSL routines:SSL3_GET_CLIENT_
HELLO:no shared cipher
Can anyone help me understand:
1) What these errors mean
2) Why I'm getting them, It was not coming with the older version of server.py code applicable to iphone 4s?
3) How I can go about fixing these
Thanks,
Vivek
This is because APNSWrapper hasn't been updated to TLSv1 yet.
Apple no longer supports sslv3 for MDM due to the POODLE vulnerability.
You can update APNSWrapper source yourself though pretty easily.
download the source and update connection.py
ssl_version = self.ssl_module.PROTOCOL_TLSv1,
the run
python setup.py install
I have a long running python script, launched with upstart. This script makes quite a lot of requests. Everything works well at first, however after a few hours I start permanently getting the following error for each request:
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/client.py", line 119, in request
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/http_core.py", line 420, in request
File "/opt/a/a-env/local/lib/python2.7/site-packages/atom/http_core.py", line 489, in _http_request
File "/usr/lib/python2.7/httplib.py", line 931, in endheaders
File "/usr/lib/python2.7/httplib.py", line 794, in _send_output
File "/usr/lib/python2.7/httplib.py", line 756, in send
File "/usr/lib/python2.7/httplib.py", line 1134, in connect
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
gaierror: [Errno -3] Temporary failure in name resolution
This is not a problem with name resolution or DNS, because a simple restart of the application fixes this problem.
I've tried both Python 2.6 a 2.7 and the same situation occurs.
I'm running Linux 2.6.35-30-virtual #61-Ubuntu SMP Tue Oct 11 18:26:36 UTC 2011 x86_64 GNU/Linux
There have been a few posts with this problem, but none with a straightforward explanation or solution:
https://github.com/ggstuart/greenview/issues/4
Permanent 'Temporary failure in name resolution' after running for a number of hours
I think this happens when you get in a "too many open files" condition. Next time this happens, try to see how many file descriptors your script has open.
The root cause is that /etc/resolv.conf is only read at python startup. To force a refresh of the resolve table, you can run this (on Linux):
import ctypes
libc = ctypes.cdll.LoadLibrary('libc.so.6')
res_init = libc.__res_init
res_init()