TL;博士 :-)获取https urls在python和R中都有效,但当从R运行python代码时则不然。
在运行 RKeras 软件包文档中的一些代码时,我反复遇到致命错误:"unknown url type: https"
问题源于在 Python 中实现的 Keras。
我深入研究了这个问题,发现当 Keras 调用模块中的函数urlretrieve
时就会发生这种情况six
从 https url 检索数据。
然后我在iPython中测试了代码,发现它运行良好。
<!-- language: lang-python -->
from six.moves.urllib.request import urlretrieve
urlretrieve(url="https://www.google.com")
然后我尝试在 R 中做同样的事情,但它失败了
<!-- language: lang-r -->
library(reticulate)
py_run_string('from six.moves.urllib.request import urlretrieve')
py_run_string("urlretrieve(url='https://www.google.com')")
但是,同样的事情在 R 中使用纯 http 工作
<!-- language:lang-r -->
py_run_string("urlretrieve(url='http://www.google.com')")
作为记录,https 在我的 R 中使用 httr 等包运行良好。
我在这里完全不知所措。可能会发生什么?
这是关于我的环境的一些输出
R:
sessionInfo()
# R version 3.4.4 (2018-03-15)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Ubuntu 16.04.4 LTS
# other attached packages:
# [1] reticulate_1.6 kerasR_0.8.0
和Python(从R中看到)
py_config()
version: 3.5.2 |Anaconda custom (64-bit)|
(default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
非常感谢您的时间和精力。
编辑:R 中的更多调试信息:
py_run_string("from OpenSSL import SSL")
# ImportError: /xxx/python3.5/lib-dynload/_ssl.so: undefined symbol: SSLv2_method
目前,我正在发布针对我的特定问题的部分解决方案。这不会解决Reticulate和SSL的一般问题,但是一个不错的临时解决方法,可以帮助任何使用KerasR或Keras的人发现它无法下载模型和数据库。
Keras/KerasR 使用缓存来避免将来下载同一对象。就我而言,这是~/.keras/
因此,从控制台复制下载失败的 URL,使用浏览器下载对象并保存到 keras 的缓存目录中。
cache for models : ~/.keras/models/
cache for datasets : ~/.keras/datasets/
(where ~ is my home directory)
当然,这是一种解决方法,我仍然期待有人发布适用于整个系统的适当解决方案。