测试需要修改系统时间之后, 引起https证书过期问题

开发测试的时候,我们经常需要倒退时间。倒推时间,请求https相关资源的时候,自然引起证书的问题:

    return self.__request(url)
  File "build/bdist.linux-x86_64/egg/curl/__init__.py", line 87, in __request
    self.handle.perform()
error: (60, 'Peer certificate cannot be authenticated with known CA certificates')


curl -v https://api.weixin.qq.com/sns/oauth2/access_token

* About to connect() to api.weixin.qq.com port 443 (#0)
*   Trying 183.61.49.149... connected
* Connected to api.weixin.qq.com (183.61.49.149) port 443 (#0)
* Initializing NSS with certpath: /etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* Remote Certificate has expired.
* NSS error -8181
* Closing connection #0
* Peer certificate cannot be authenticated with known CA certificates
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html


curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

证书过期了,最简单的办法,就是不验证证书。如下:

#coding=utf8
#!/bin/python2.6

import pycurl
import curl

url = "https://api.weixin.qq.com/sns/oauth2/access_token"
cc = curl.Curl()
cc.set_option(pycurl.SSL_VERIFYPEER, 0)  # 加这一行
r = cc.get(url)
print r


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值