python requests.get https 日志

爬取目标是https站点,目前环境是python2.7。

requests.get("https://blog.pucipuci.cn/checkip.php",verify=False)

报警告

/var/python2.7/lib/python2.7/site-packages/urllib3/util/ssl_.py:339: SNIMissingWarning: An HTTPS request has been made, but 

the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an 

incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. 

For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  SNIMissingWarning
/var/python2.7/lib/python2.7/site-packages/urllib3/util/ssl_.py:137: InsecurePlatformWarning: A true SSLContext object is not 

available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can 

upgrade to a newer version of Python to solve this. For more information, see 

https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecurePlatformWarning
<Response [200]>

虽然报警告,但内容还是有的。<Response [200]>

处理

pip install pyopenssl ndg-httpsclient pyasn1

安装失败
报错中有一个 No package 'libffi' found
处理

yum install libffi-devel

虽然安装失败,但无法再重新安装 必须卸载原安装的包

pip uninstall pyopenssl ndg-httpsclient pyasn1
pip install pyopenssl ndg-httpsclient pyasn1

报错:Could not find .egg-info directory in install record for cryptography>=1.9 (from pyopenssl)
处理

pip install --upgrade setuptools pip
pip uninstall pyopenssl ndg-httpsclient pyasn1
pip install pyopenssl ndg-httpsclient pyasn1

再运行

requests.get("https://blog.pucipuci.cn/checkip.php",verify=False)

还有一行警告,

/var/python2.7/lib/python2.7/site-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is 

being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-

usage.html#ssl-warnings
  InsecureRequestWarning)
<Response [200]>

去掉 verify=False

requests.get("https://blog.pucipuci.cn/checkip.php",verify=False)

成功

html = requests.get("https://blog.pucipuci.cn/checkip.php")
print(html.content)

输出正确内容,无警告。

转载请注明出处:https://www.isres.com/linux/50.html

发表留言

人生在世,错别字在所难免,无需纠正。

    captcha