问题描述
因此,我正在尝试使用Gmail API获取邮件消息,对其进行解析,然后将其另存为JSON文件。 到目前为止,我成功做到了,但是我是同步完成的。 当我尝试使用Threadpool同时执行这些请求时,问题就开始了。 Python 3.7
我遇到错误:ssl.SSLError:[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2555)
如果有人知道此错误或可以告诉我什么地方出了问题,我将不胜感激。 谢谢!
connector.py
def create_msg_objects(self,messages):
""" Creates a List of Gmailodel objects from a list of messages-id.
Keyword arguments:
mesages -- List of unread messages,message: {id: str,trackId: str}
Return:
List of GmailModel objects
"""
if messages is None:
logger.error('messages argument is None!')
msg_objects = []
msgs_list = [message['id'] for message in messages]
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
futures = {executor.submit(self.gmailAPI.get_message,msg_id) : msg_id for msg_id in msgs_list}
for future in concurrent.futures.as_completed(futures):
# try:
data = future.result()
msg_objects.append(self._create_msg_obj(data))
# except Exception as exc:
# print('generated an exception: %s' % (exc))
# else:
# print('%r page is %d bytes' % (len(data)))
gmail.py
def get_message(self,msg_id,userId='me'):
""" Get a full description of message by its id.
Keyword arguments:
userId -- User mail (default 'me')
msg_id -- The id of the message to get its description
"""
logger.log('Starting get_message')
try:
message = self.service.users().messages().get(userId=userId,id=msg_id,format='raw').execute()
return message
except errors.HttpError as error:
print('An error occurred: %s',error)
logger.error('An error occurred: %s',error)
堆栈跟踪:
Traceback (most recent call last):
File "script.py",line 18,in <module>
run_connector()
File "script.py",line 11,in run_connector
con.fetch_unread_msgs()
File "/Users/avivlevitzky/Desktop/Python Project/Simplify_Task/connector.py",line 41,in fetch_unread_msgs
msg_objects = self.create_msg_objects(messages)
File "/Users/avivlevitzky/Desktop/Python Project/Simplify_Task/connector.py",line 64,in create_msg_objects
data = future.result()
File "/opt/anaconda3/lib/python3.7/concurrent/futures/_base.py",line 428,in result
return self.__get_result()
File "/opt/anaconda3/lib/python3.7/concurrent/futures/_base.py",line 384,in __get_result
raise self._exception
File "/opt/anaconda3/lib/python3.7/concurrent/futures/thread.py",line 57,in run
result = self.fn(*self.args,**self.kwargs)
File "/Users/avivlevitzky/Desktop/Python Project/Simplify_Task/gmail.py",line 126,in get_message
format='raw').execute()
File "/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/_helpers.py",line 134,in positional_wrapper
return wrapped(*args,**kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/http.py",line 901,in execute
headers=self.headers,File "/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/http.py",line 204,in _retry_request
raise exception
File "/opt/anaconda3/lib/python3.7/site-packages/googleapiclient/http.py",line 177,in _retry_request
resp,content = http.request(uri,method,*args,**kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/google_auth_httplib2.py",line 201,in request
uri,body=body,headers=request_headers,**kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py",line 1994,in request
cachekey,File "/opt/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py",line 1651,in _request
conn,request_uri,body,headers
File "/opt/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py",line 1589,in _conn_request
response = conn.getresponse()
File "/opt/anaconda3/lib/python3.7/http/client.py",line 1344,in getresponse
response.begin()
File "/opt/anaconda3/lib/python3.7/http/client.py",line 306,in begin
version,status,reason = self._read_status()
File "/opt/anaconda3/lib/python3.7/http/client.py",line 267,in _read_status
line = str(self.fp.readline(_MAXLINE + 1),"iso-8859-1")
File "/opt/anaconda3/lib/python3.7/socket.py",line 589,in readinto
return self._sock.recv_into(b)
File "/opt/anaconda3/lib/python3.7/ssl.py",line 1071,in recv_into
return self.read(nbytes,buffer)
File "/opt/anaconda3/lib/python3.7/ssl.py",line 929,in read
return self._sslobj.read(len,buffer)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2555)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)