首页 版块 访问AI主站 注册 发帖
PSNNoflowers
6
积分 积分商城
0
获赞
requests.exceptions.SSLE
Ta的回复 :另外我也尝试了站内大神的代码,如下 import urllib3,base64 from urllib.parse import urlencode access_token="24.6e78aa6e66a70f9ba03b6e9454a2d856.2592000.1561380623.282335-16345188" http=urllib3.PoolManager() url='https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token='+access_token f = open('C:/Users/Qin/Pictures/abc.jpg','rb') #参数image:图像base64编码 以及face_fields参数 #image的值取决于 image_type img = base64.b64encode(f.read()) ##params 把三种值请求都给出了 测试请自己选择是用BASE64 FACE_TOKEN URL哪个。剩下的2个params注释掉 一定要自己看看文档 URL给的那个图片网络地址只是示例并不是一个真正可以访问的图片网络地址 params={'image':''+str(img,'utf-8')+'','image_type':'BASE64','face_field':'age,beauty,faceshape,gender,glasses'} #params={'image':'f7ec8ecd441886371b9749d1fc853f44','image_type':'FACE_TOKEN','face_field':'age,beauty,faceshape,gender,glasses'} #params={'image':'https://www.xsshome.cn/face.jpg','image_type':'URL','face_field':'age,beauty,faceshape,gender,glasses'} #对base64数据进行urlencode处理 params=urlencode(params) request=http.request('POST', url, body=params, headers={'Content-Type':'application/json'}) #对返回的byte字节进行处理。Python3输出位串,而不是可读的字符串,需要进行转换 result = str(request.data,'utf-8') print(result) ################分割线################# 也是同样的报错具体全部如下: Traceback (most recent call last): File "D:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 588, in urlopen conn = self._get_conn(timeout=pool_timeout) File "D:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 248, in _get_conn return conn or self._new_conn() File "D:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 816, in _new_conn raise SSLError("Can't connect to HTTPS URL because the SSL " urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\anaconda3\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "D:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "D:\anaconda3\lib\site-packages\urllib3\util\retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='aip.baidubce.com', port=443): Max retries exceeded with url: /oauth/2.0/token?grant_type=client_credentials&client_id=W6P53RdhzPjkpduAD47yZhc3&client_secret=zPEpKy8ZoGH6rGOKGjrVINVEMbPoCssW (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Qin/PycharmProjects/qin/face.py", line 12, in print(client.detect(image64, "BASE64", None)) File "D:\anaconda3\lib\site-packages\aip\face.py", line 67, in detect 'Content-Type': 'application/json', File "D:\anaconda3\lib\site-packages\aip\base.py", line 89, in _request authObj = self._auth() File "D:\anaconda3\lib\site-packages\aip\base.py", line 165, in _auth ), proxies=self._proxies).json() File "D:\anaconda3\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "D:\anaconda3\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "D:\anaconda3\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "D:\anaconda3\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "D:\anaconda3\lib\site-packages\requests\adapters.py", line 514, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='aip.baidubce.com', port=443): Max retries exceeded with url: /oauth/2.0/token?grant_type=client_credentials&client_id=W6P53RdhzPjkpduAD47yZhc3&client_secret=zPEpKy8ZoGH6rGOKGjrVINVEMbPoCssW (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
1
切换版块
智能客服