Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from XiaoMiku01:master #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions onepush/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# import requests
from aiohttp import ClientSSLError, ClientSession, TCPConnector

from ssl import SSLCertVerificationError

# from requests.exceptions import SSLError

Expand Down Expand Up @@ -76,12 +76,15 @@ async def request(self, method, url: str, **kwargs):
# )
# response = None
try:
sessions = []
if self.proxy:
connector = ProxyConnector.from_url(self.proxy)
session = ClientSession(connector=connector, trust_env = True)
sessions.append(session)
response = await session.request(method, url, **kwargs)
else:
session = ClientSession(trust_env = True)
sessions.append(session)
response = await session.request(method, url, **kwargs)
# log.debug('Response: {}'.format(response.text))
except ClientSSLError as e:
Expand All @@ -91,12 +94,24 @@ async def request(self, method, url: str, **kwargs):
else:
connector = TCPConnector(verify_ssl=False)
session = ClientSession(connector=connector, trust_env = True)
sessions.append(session)
response = await session.request(method, url.replace('https', 'http'), proxy=self.proxy, **kwargs)
# log.debug('Response: {}'.format(response.text))
except SSLCertVerificationError as e:
log.error(e)
if self.proxy:
connector = ProxyConnector.from_url(self.proxy, verify_ssl=False)
else:
connector = TCPConnector(verify_ssl=False)
session = ClientSession(connector=connector, trust_env = True)
sessions.append(session)
response = await session.request(method, url, proxy=self.proxy, **kwargs)
# log.debug('Response: {}'.format(response.text))
except Exception as e:
log.error(e)
finally:
await session.close()
for session in sessions:
await session.close()
return response

async def notify(self, **kwargs):
Expand Down