truffle init/unbox时遇到 Got error: connect ECONNREFUSED 151.101.196.133:443. Please check the format

这两天依旧在truffle的各种bug之间兜兜转转,今天要分享的是这样的问题:

Error: Error making request to https://raw.githubusercontent.com/truffle-box/bare-box/master/truffle.js. Got error: connect ECONNREFUSED 151.101.192.133:443. Please check the format of the requested resource.

truffle init/unbox时遇到 Got error: connect ECONNREFUSED 151.101.196.133:443. Please check the format

关键要看的错误信息是:connect ECONNREFUSED 151.101.192.133:443

什么意思?连接github的某个网页被拒绝了。

什么原因?网络配置有问题,和你连接的网络,或者你的网络的一些设置有关。

如何解决?我找到了两个办法:

1.换一个网络试一试,比如我之前连接的是校园网,后来换成了手机的热点,就可以。

2.修改hosts文件:

  (1)Windows下:(这部分摘自https://blog.csdn.net/weixin_40089510/article/details/85936724

truffle init/unbox时遇到 Got error: connect ECONNREFUSED 151.101.196.133:443. Please check the format

找到这个路径,然后找到hosts文件(没有任何后缀的那个),然后修改内容,添加进github相关的所有ip。

从下面开始。
#127.0.0.1 gilisoft.com
#github
192.30.253.113 github.com
192.30.253.113 github.com
192.30.253.118 gist.github.com
192.30.253.119 gist.github.com

GitHub Start
192.30.253.112 github.com
192.30.253.119 gist.github.com
151.101.100.133 assets-cdn.github.com
151.101.100.133 raw.githubusercontent.com
151.101.100.133 gist.githubusercontent.com
151.101.100.133 cloud.githubusercontent.com
151.101.100.133 camo.githubusercontent.com
151.101.100.133 avatars0.githubusercontent.com
151.101.100.133 avatars1.githubusercontent.com
151.101.100.133 avatars2.githubusercontent.com
151.101.100.133 avatars3.githubusercontent.com
151.101.100.133 avatars4.githubusercontent.com
151.101.100.133 avatars5.githubusercontent.com
151.101.100.133 avatars6.githubusercontent.com
151.101.100.133 avatars7.githubusercontent.com
151.101.100.133 avatars8.githubusercontent.com

其实关键是要把你报错的那条ip加进去,比如我遇到的是151.101.192.133:443,那么我应该也把151.101.192.133加进去。

  (2)Ubuntu下:

hosts在etc文件夹下,对照上面的内容修改即可。

 

但是这时,当你再次truffle init或者unbox的时候,你可能会像我一样,出现下面的问题:

Truffle Box at URL https://github.com/truffle-box/bare-box.git doesn't exist. If you believe this is an error, please contact Truffle support.

truffle init/unbox时遇到 Got error: connect ECONNREFUSED 151.101.196.133:443. Please check the format

下面这部分摘自https://www.jianshu.com/p/e3ea54ed8d3a

解决方法可以是直接git代码取代truffle init命令

git clone https://github.com/truffle-box/bare-box

后续的命令需要先执行:

cd bare-box

后继续照旧