本地運行項目成功 ,但在服務器運行程序就會報Failed to establish a new connection: [Errno -2] Name or service not known


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



再次運行腳本就可以正常執行了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM