python ConnectionError 或 curl Could not resolve host

问题

问题一

使用python访问指定url时报错

requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.lyczkj.gov.cn', port=80): Max retries exceeded with url: /index.php?r=default (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f497d4909d0>: Failed to establish a new connection: [Errno -2] Name or service not known',))

问题二

使用curl访问指定url时报错

curl: (6) Could not resolve host: www.lyczkj.gov.cn

解决办法

1:使用root用户登录
2:编辑resolv.conf文件

vi /etc/resolv.conf

3:在文件底部添加dns

nameserver 8.8.8.8
nameserver 8.8.4.4

参考

https://stackoverflow.com/questions/24967855/curl-6-could-not-resolve-host-google-com-name-or-service-not-known

你可能感兴趣的:(linux,python)