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:
print(response.version)
print(response.status)
print(response.connection)
print(response.url)
certificate = response.connection.transport.get_extra_info(“peercert”)
issuer = certificate[“issuer”]
temp_list = []
for item in issuer:
temp_list.append(item[0])
temp_tuple = tuple(temp_list)
ssl_dict = dict(temp_tuple)
page = await response.text()
response.connection.release()
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 = https://practicalmarketing.io

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.