欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎樣用原生的urllib2+httplib請(qǐng)求Https

本篇文章給大家分享的是有關(guān)怎樣用原生的urllib2+httplib請(qǐng)求Https,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了安陸免費(fèi)建站歡迎大家使用!

環(huán)境

python2.7.5

# https server 生成證書

https://www.cnblogs.com/loleina/p/8418111.html

# HTTPSConnection

key        # https server使用的key

ca_certs # https server使用的ca

cert        # 在 瀏覽器下載的證書, windows下載后linux可以使用

### https.py

import urllib2, httplib, ssl, socket

DEFAULT_HTTP_TIMEOUT = 10 #seconds

# http://code.activestate.com/recipes/577548-https-httplib-client-connection-with-certificate-v/

# http://stackoverflow.com/questions/1875052/using-paired-certificates-with-urllib2

class HTTPSClientAuthHandler(urllib2.HTTPSHandler):

    '''

    Allows sending a client certificate with the HTTPS connection.

    This version also validates the peer (server) certificate since, well...

    WTF IS THE POINT OF SSL IF YOU DON"T AUTHENTICATE THE PERSON YOU"RE TALKING TO!??!

    '''

    def __init__(self, key=None, cert=None, ca_certs=None, ssl_version=None, ciphers=None):

        urllib2.HTTPSHandler.__init__(self)

        self.key = key

        self.cert = cert

        self.ca_certs = ca_certs

        self.ssl_version = ssl_version

        self.ciphers = ciphers

    def https_open(self, req):

        # Rather than pass in a reference to a connection class, we pass in

        # a reference to a function which, for all intents and purposes,

        # will behave as a constructor

        return self.do_open(self.get_connection, req)

    def get_connection(self, host, timeout=DEFAULT_HTTP_TIMEOUT):

        return HTTPSConnection( host, 

                key_file = self.key, 

                cert_file = self.cert,

                timeout = timeout,

                ciphers = self.ciphers,

                ca_certs = self.ca_certs )

class HTTPSConnection(httplib.HTTPSConnection):

    '''

    Overridden to allow peer certificate validation, configuration

    of SSL/ TLS version and cipher selection.  See:

    http://hg.python.org/cpython/file/c1c45755397b/Lib/httplib.py#l1144

    and `ssl.wrap_socket()`

    '''

    def __init__(self, host, **kwargs):

        self.ciphers = kwargs.pop('ciphers',None)

        self.ca_certs = kwargs.pop('ca_certs',None)

        self.ssl_version = kwargs.pop('ssl_version', ssl.PROTOCOL_SSLv23)

        httplib.HTTPSConnection.__init__(self,host,**kwargs)

    def connect(self):

        sock = socket.create_connection( (self.host, self.port), self.timeout )

        if self._tunnel_host:

            self.sock = sock

            self._tunnel()

        self.sock = ssl.wrap_socket( sock, 

                keyfile = self.key_file, 

                certfile = self.cert_file,

                ca_certs = self.ca_certs,

                cert_reqs = ssl.CERT_REQUIRED if self.ca_certs else ssl.CERT_NONE )

### test.py

import urllib2

import urllib

import https

import ssl

import json

client_cert_key = "etcd-client-key.pem" # file path

client_cert_pem = "etcd-client.pem"     # file path 

ca_certs = "etcd-ca.pem"                # file path

handlers = []

handlers.append( https.HTTPSClientAuthHandler( 

    key = client_cert_key,

    cert = client_cert_pem,

    ca_certs = ca_certs,

    ssl_version = ssl.PROTOCOL_SSLv23,

    ciphers = 'TLS_RSA_WITH_AES_256_CBC_SHA' ) )

http = urllib2.build_opener(*handlers)

# request https

# GET

resp = http.open('https://xxxx:2379/v2/members')

data = resp.read()

# POST

req = urllib2.Request(url)  

data = urllib.urlencode(data)

resp = http.open(req, data)

# PUT

request = urllib2.Request(url, data=json_data)

request.add_header('Content-Type', 'application/json')

request.get_method = lambda: 'PUT'

resp = http.open(request)

# DELETE

request = urllib2.Request(url, data=data)

request.get_method = lambda: 'DELETE'

resp = http.open(request)

resp.close()

以上就是怎樣用原生的urllib2+httplib請(qǐng)求Https,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞名稱:怎樣用原生的urllib2+httplib請(qǐng)求Https
分享網(wǎng)址:http://aaarwkj.com/article4/giphie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷網(wǎng)站策劃、電子商務(wù)面包屑導(dǎo)航響應(yīng)式網(wǎng)站、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
精品人妻一区二区av| 欧美日韩国产另类久久| 国模一区二区三区视频| 一区二区尤物区亚洲国产精品区| 久久青草精品欧美日韩精品| 国产精品自产在线观看一| 免费在线一区二区av| 一区二区三区福利视频在线观看| 亚洲综合日韩精品在线| 星空无限传媒国产最新| 国产高清毛片区1区二区三区| 亚洲精品隔壁傲慢人妻| 日韩欧美亚洲视频另类| 亚洲av蜜臀在线播放| 精品久久久久久久久无| 九九在线视频精品免费播放| 国产激情视频在线观看你懂的| 精品传媒国产在线观看| 久久久偷拍美女撒尿尿| 欧美精品黑人三级精品| 国产综合中文字幕不卡| 久久精品国产亚洲av麻豆尤物| 黄片视频免费在线播放大全| 亚洲国产综合六月深深爱| 欧美日韩电影一区二区三区| 国产精品一区二区三区欧美| 国产日韩精品欧美综合区| 97在线视频观看官网| 久久偷拍精品视频久久| 日本经典三级视频在线观看| 亚洲老熟女老妇老女人| 欧美一区二区男人天堂| 日本新任女教师在线播放| 亚洲免费一区二区三区精品| 亚洲一区二区精品天堂| 五月婷婷丁香在线观看| 国产,欧美,日韩,日日骚| 丁香六月婷婷激情啪啪综合| 在线麻豆国产传媒免费| 亚洲欧美二区中文字幕| 最新免费观看男女啪啪视频|