Response connection is None

I’m working on a web crawler, and about 25% of the time, it returns an error such as

‘NoneType’ object has no attribute ‘transport’

I’ve done a little testing and found that on sites that error occurs on, the response connection returns None.

Here’s my code:
async def fetch_https(url, session):
timeout = aiohttp.ClientTimeout(total=10,sock_connect=5,sock_read=5)
headers = {
‘User-Agent’: ‘Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0’
async with session.get(url, timeout=timeout, headers=headers) as response:
certificate = response.connection.transport.get_extra_info(“peercert”)
issuer = certificate[“issuer”]
temp_list = []
for item in issuer:
temp_tuple = tuple(temp_list)
ssl_dict = dict(temp_tuple)
page = await response.text()
return SiteResponse(page, certificate[“notAfter”], ssl_dict[“organizationName”], ssl_dict[“commonName”])

Here’s what I get from the print statements:

response.version = HttpVersion(major=1, minor=1)
response.status = 200
response.connection = None
response.url =

I’m not sure if the connection is being closed before I can query it for some reason? Or maybe it’s not even established yet due to an error in my async setup?

Any help would be appreciated.