python - Python SSL Cert error despite no browser expiry
问题描述
I am a python noob and was trying to scrape random websites (without abusing). This site caught my attention and my code ran:-
import requests
url = 'https://resultsarchives.nic.in/cbseresults/cbseresults2018/class12zpq/class12th18.asp'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "en-US,en;q=0.9,bn;q=0.8",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
":authority": "resultsarchives.nic.in",
"Origin": "http://resultsarchives.nic.in",
"Referer": "https://resultsarchives.nic.in/cbseresults/cbseresults2018/class12zpq/class12th18.htm",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
}
x = range(8397, 8398)
i=0
for i in x:
payload = {
'regno': '6529437',
'sch': '12345',
'cno': str(i),
'B2': 'Submit'
}
response = requests.post(url, headers=headers, data=payload)
open('scrape.html', 'a', encoding="utf-8").write(response.text)
When executed, an SSL Certificate Expiry Error is thrown. However, browsers (chrome/firefox) work fine, and note the certificate to expire in Dec. 2022. The error ran:
requests.exceptions.SSLError: HTTPSConnectionPool(host='resultsarchives.nic.in', port=443): Max retries exceeded with url: /cbseresults/cbseresults2018/class12zpq/class12th18.asp (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)')))
If I process the same code using the Http version(s) of the site(s), it works fine!
解决方案
推荐阅读
- python - AttributeError:“生成器”对象没有属性“to_sql”使用生成器创建数据框时
- javascript - 数据表和行详细信息
- php - Nginx 快速 CGI 缓存 ON error_page 404
- php - PHP 错误:致命错误:未捕获的 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;
- dart - 如何将 `ByteData` 实例写入 Dart 中的文件?
- python - 在 SqlAlchemy 中加入时如何将子查询对象转换为 ResultProxy 类?
- c# - IdentityServer3 - 错误 Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException:IDX10503:签名验证失败
- mysql - 从 SQL 列中删除所有字母
- java - 操作栏后退键不起作用
- php - 使用 git 终端时,laravel homestead “找不到驱动程序”