URLError fetching VGG16 [duplicate] - python

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'

Related

Lets Encrypt 403 Error When Installing certbot-auto on legacy (EOL) SNI is required error

Good day,
I am trying to create a test server with an EOL set up - Ubuntu 14.04, php5.5.
I am trying to install certbot-auto 1.9.0. I understand this is EOL and really shouldn't be used. However, we do have servers which are still using it successfully with little issues.
When I am trying to install certbot-auto 1.9.0 I am receiving the following error. Is there anyway to get around this issue?
Installing Python packages...
Traceback (most recent call last):
File "/tmp/tmp.KuBN6fzZPB/pipstrap.py", line 182, in <module>
sys.exit(main())
File "/tmp/tmp.KuBN6fzZPB/pipstrap.py", line 163, in main
for path, digest in PACKAGES]
File "/tmp/tmp.KuBN6fzZPB/pipstrap.py", line 122, in hashed_download
response = opener(using_https=parsed_url.scheme == 'https').open(url)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: SNI is required```
According to this answer on the LetsEncrypt discussion board, it's not possible to use Certbot/certbot-auto at all with Ubuntu 14.04 anymore (likely because Certbot tries to update itself, and is no longer able to on Ubuntu 14.04).
acme.sh is a different LetsEncrypt client that possibly works.

Is it possible to connect to a https URL?

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.

urllib HTTPS request: <urlopen error unknown url type: https>

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'

VirtualEnv: Creating virtual environment fails in Win 7

Just got python, pip and virtualenv installed on my windows 7 box.
Ran into the following issues when I want to create a virtual enviroment:
virtualenv test gives me:
------------------------------------------------------------
-c run on 09/18/14 00:24:25
Ignoring indexes: https://pypi.python.org/simple/
Downloading/unpacking setuptools
Cleaning up...
Removing temporary dir C:\Users\Han\test\build...
Exception:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\req.py", line 1177, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 209, in find_requirement
file_locations, url_locations = self._sort_locations(locations)
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 128, in _sort_locations
sort_path(os.path.join(path, item))
File "c:\python27\lib\site-packages\virtualenv_support\pip-1.5.6-py2.py3-none-any.whl\pip\index.py", line 109, in sort_path
if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
File "c:\python27\Lib\mimetypes.py", line 287, in guess_type
init()
File "c:\python27\Lib\mimetypes.py", line 348, in init
db.read_windows_registry()
File "c:\python27\Lib\mimetypes.py", line 256, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
WindowsError: [Error 2] The system cannot find the file specified
any ideas? Have tried using the registry checker as well as hard coding the mimetypes.py file: http://www.swarley.me.uk/blog/2014/04/23/python-pip-and-windows-registry-corruption/ but the same error still occurs.
You're getting a different specific error message from the read_windows_registry() function than the one I talked about in my blog post, so I don't think deleting/skipping corrupted registry keys containing null characters is going to work for you.
I just found issue #505 in the virtualenv project which seems to be talking about your specific problem. There are several recommendations in that thread - do any of those solve your problem? It looks like the problem was subsequently fixed by pull request #579 anyway, so perhaps you just need to update to a newer version of virtualenv?

SSL Handshake Error while connecting to Server via web client

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

Categories