码迷,mamicode.com
首页 > 其他好文 > 详细

本地运行项目成功 ,但在服务器运行程序就会报Failed to establish a new connection: [Errno -2] Name or service not known

时间:2019-06-17 15:56:16      阅读:2351      评论:0      收藏:0      [点我收藏+]

标签:mat   oss   image   min   增加   with ur   tps   mamicode   ati   

equests.exceptions.ConnectionError: HTTPSConnectionPool(host=appapi.xxxx.com, port=443): Max retries exceeded with url: /appapi/exchange/19/v1/prolist (Caused by NewConnectionError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7fca889818d0>: Failed to establish a new connection: [Errno -2] Name or service not known,))

 

排查request连接 错误 ,说明是和网络 相关的,

step1:先在服务器端ping 一下测试网址的host

(automationVenv) [root@67 automationTest]# ping appapi.xxx.com
PING appapi.5i5j.com.wswebpic.com (103.254.190.254) 56(84) bytes of data.
64 bytes from 103.254.190.254 (xxx.254.190.254): icmp_seq=1 ttl=55 time=2.93 ms
64 bytes from 103.254.190.254 (xxx.254.190.254): icmp_seq=2 ttl=55 time=2.56 ms
64 bytes from 103.254.190.254 (xxx.254.190.254): icmp_seq=3 ttl=55 time=4.97 ms
64 bytes from 103.254.190.254 (xxx.254.190.254): icmp_seq=4 ttl=55 time=3.07 ms

step2:在本地ping 一下测试网址的host

wangju@wangju-HP-348-G4:~$ ping appapi.xxx.com
PING appapi.xxx.com (47.95.31.237) 56(84) bytes of data.
64 bytes from 47.95.31.237 (47.95.31.237): icmp_seq=1 ttl=91 time=5.18 ms
64 bytes from 47.95.31.237 (47.95.31.237): icmp_seq=2 ttl=91 time=3.94 ms
^C
--- appapi.xxx.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 3.948/4.567/5.186/0.619 ms

观查到服务端和本地 同一host指向的ip不一样

解决 办法 就是在服务器端 配置被测网址的host与本地一样

nano /etc/hosts

增加内容如下:

47.95.31.237 appapi.xxx.com



技术图片

再次运行脚本就可以正常执行了

技术图片

 

本地运行项目成功 ,但在服务器运行程序就会报Failed to establish a new connection: [Errno -2] Name or service not known

标签:mat   oss   image   min   增加   with ur   tps   mamicode   ati   

原文地址:https://www.cnblogs.com/kaerxifa/p/11039863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!