Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1743493
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: Python/Ruby

2016-04-26 11:46:23

这到底是为什么会出错,我实在是想不明白。

点击(此处)折叠或打开

  1. def request_func1():
  2.     url=""
  3.     #url=urllib.request.Request("")
  4.     try:
  5.         data=urllib.request.urlopen(url).read().decode()
  6.     except urllib.error.HTTPError as error:
  7.         print(error.code,error.reason,error.headers)
  8.     except urllib.error.URLError as error:
  9.         print(error.reason)
  10.     print(data)

  11. request_func1()
参考了下这里:http://stackoverflow.com/questions/32115607/python-3-4-ssl-error-urlopen-error-eof-occurred-in-violation-of-protocol-ssl-c

点击(此处)折叠或打开

  1. def func3():
  2.     from requests.adapters import HTTPAdapter
  3.     from requests.packages.urllib3.poolmanager import PoolManager
  4.     import ssl

  5.     class MyAdapter(HTTPAdapter):
  6.         def init_poolmanager(self, connections, maxsize, block=False):
  7.             self.poolmanager = PoolManager(num_pools=connections,maxsize=maxsize,block=block,ssl_version=ssl.PROTOCOL_TLSv1)


  8.     import requests
  9.     s=requests.Session()
  10.     s.mount('https://',MyAdapter())
  11.     data=s.get("",verify=False)
  12.     print(data.text)
后来我把这个去掉,感觉requests 也是可以用的,好奇怪

点击(此处)折叠或打开

  1. import requests
  2. data=requests.get("",verify=False)
  3. print(data.text)
真的太诡异了
阅读(6086) | 评论(0) | 转发(0) |
0

上一篇:python 多线程示例1

下一篇:python的set 操作

给主人留下些什么吧!~~