ROS:sudo rosdep init出错常规方法都无效后解决办法记录

参照网上进行ubuntu16.04系统下ROS平台安装时(例如Ubuntu16.04下的ROS安装),在初始化rosdep时报错,20-default.list无法下载:

sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

google查找了很多解决办法(例如rosdep init gives "Website may be down." · Issue #9721 · ros/rosdistro),网上典型热门解决方法如下:

1)ca-certificates问题,证书不对,重新安装证书

sudo apt-get install ca-certificates

2)系统时间同步问题,需要同步系统时间

参照链接https://blog.csdn.net/A18373279153/article/details/81003937进行系统时间同步

sudo apt-get install ntpdate
sudo ntpdate cn.pool.ntp.org
sudo hwclock --systohc

3) 还是ssl certs问题,继续尝试解决

sudo c_rehash /etc/ssl/certs 
sudo -E rosdep init

4)python-rosdep问题

sudo apt-get install python-rosdep

但以上方法全部无效,无奈之下直接在/etc目录下新建/ros/rosdep/sources.list.d/20-default.list文件(注意sudo rosdep init失败时,/etc下并没有/ros目录,需要依次逐级新建),然后将https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list内容粘贴进去,如下:

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

至此,终于解决了20-default.list下载不下来的问题。

注:这里虽然手动新建了20-default.list,但执行sudo rosdep init依然会出现之前的错误,这里我们无视,继续执行下一步。

2.下一步,接下来进行升级,可惜还是报错:

rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
	<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
	<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
	<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
	<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
	Failed to download target platform data for gbpdistro:
	<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
	<urlopen error <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)> (https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml)>

看ERROR是urlopen和ssl验证的问题,虽然已经可以读取我们手动新建的20-default.list中的内容,但并没有解决根本问题,要下载东西时依然出错。

报的错误原因是python 升级到 2.7.9 之后引入了一个新特性,当使用urllib.urlopen打开一个 https 链接时,会验证一次 SSL 证书,而当目标网站使用的是自签名的证书时就会抛出一个 urllib2.URLError的错误消息。

既然前面尝试了很多办法都没法解决SSL验证问题,那只能想办法在执行rosdep update时尝试定位urllib.urlopen()函数并规避掉SSL验证。

搜了很久,终于找到Z-HE:sudo rosdep init出错的解决方案,定位rosdep命令中用到的urllib.urlopen()

rosdep命令是py脚本,入口:
查找rosdep地址: /usr/bin/rosdep
查看rosdep.py内容:from rosdep2.main import rosdep_main
查找rosdep2地址:/usr/lib/python2.7/dist-packages/rosdep2
从main.py中进一步定位,发现是在
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py中的
download_default_sources_list()调用了urlopen()

找到urlopen()之后,如果参考链接里的解决方案,需要修改所有调用的14个地方,太复杂。如果我们可以在rosdep浅入口处设置urlopen()全局属性,取消SSL验证,那是不是可以一下解决问题?

在网上查找后发现确实可以设置SSL验证全局取消(参考Py 坑之 CERTIFICATE_VERIFY_FAILED)。

因此,在/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py中顶部直接插入两行代码取消SSL验证

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

再次rosdep update

rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Add distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
updated cache in /home/eco/.ros/rosdep/sources.cache

成功升级,至此终于完成rosdep初始化,问题解决,大功告成。

补充一条 如果再 rosdep update时候 报错“<urlopen error <urlopen error [Errno 111] Connection refused>”

解决方法:

sudo gedit /etc/resolv.conf

将原有的nameserver这一行注释,并添加以下两行:

nameserver 8.8.8.8 #google域名服务器

nameserver 8.8.4.4 #google域名服务器

发布了91 篇原创文章 · 获赞 39 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_25368751/article/details/104248464
今日推荐