Skip to content

Commit

Permalink
Merge pull request #1 from XiaoMiku01/master
Browse files Browse the repository at this point in the history
Fork Sync
  • Loading branch information
Cyberczy authored Nov 13, 2024
2 parents 30c1843 + fdc626f commit 0dae53d
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit 0dae53d

Please sign in to comment.