requests.exceptions.SSLE
PSNNoflowers 发布于2019-05 浏览:1272 回复:1
0
收藏

# -*- coding: UTF-8 -*-
import base64

from aip import AipFace

# 定义你的 APPID AK SK
APP_ID = '16345188'
API_KEY = 'W6P53RdhzPjkpduAD47yZhc3'
SECRET_KEY = 'zPEpKy8ZoGH6rGOKGjrVINVEMbPoCssW'

client = AipFace(APP_ID, API_KEY, SECRET_KEY)

imageType = "BASE64"

# 读取图片
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()

image = base64.b64encode(get_file_content('C:/Users/Qin/Pictures/abc.jpg'))

print(image)
print(str(image, 'utf-8'))
# 调用人脸检测
result = client.detect(str(image, 'utf-8'), imageType)

print(result)

#############分界线############

前面的语句都没有错误,直到client.detect(str(image, 'utf-8'), imageType)出错,错误如下:

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."))

新手请教,请轻喷。。。

收藏
点赞
0
个赞
共1条回复 最后由PSNNoflowers回复于2019-05
#2PSNNoflowers回复于2019-05

另外我也尝试了站内大神的代码,如下

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."))

0
TOP
切换版块