python asyncio - Connection reset by peer error on containers - Stack Overflow

iam using asyncio to reduce the time taken for my task through locally for below code i didnt get any e

iam using asyncio to reduce the time taken for my task through locally for below code i didnt get any error for 500 domains

but same code run on container iam facing these errors like error image

for some domains it is not giving whois response but locally it gives

the code is given below

async def detect_whois_misconfiguration(self, domain):
        registry_status = ['serverTransferProhibited', 'serverDeleteProhibited', 'serverUpdateProhibited']
        max_retries = 3
        delay_between_retries = 3
        for attempt in range(1, max_retries + 1):
            try:
                domain_info = await asyncio.to_thread(whois.whois, domain.strip('.'))
                if domain_info and domain_info.expiration_date:
                    expiration_date = domain_info.expiration_date

                    # If expiration_date is a list, take the second element
                    if isinstance(expiration_date, list):
                        expiration_date = expiration_date[1]

                    # Ensure expiration_date is a datetime object
                    if isinstance(expiration_date, str):
                        expiration_date = datetime.strptime(expiration_date, "%Y-%m-%d %H:%M:%S")
                    expiration_date = expiration_date.replace(tzinfo=timezone.utc)
                        # Get current UTC time
                    current_utc = datetime.now(timezone.utc)

                    # Compare expiration date with current time
                    if current_utc > expiration_date:
                        self.domain_expired = True
                if domain_info and domain_info.status:
                    status = domain_info.status
                    if isinstance(status, list):
                        status = " | ".join(status)
                    if not any(substring in status for substring in registry_status):
                        self.registry_lock_misconfigured = True
                    if "clientDeleteProhibited" not in status:
                        self.client_delete_misconfigured = True
                    if "clientUpdateProhibited" not in status:
                        self.client_update_misconfigured = True
                return True
            except Exception as e:
                logger.warning(f"Attempt {attempt}: Error in WHOIS info for domain {domain}, error: {e}")
                if attempt < max_retries and ('timed out' in str(e).lower() or 'connection reset by peer' in str(e).lower()):
                    logger.info(f"Retrying in {delay_between_retries} seconds...")
                    await asyncio.sleep(delay_between_retries)
                else:
                    logger.error(f"Failed to fetch WHOIS info for domain {domain} after {max_retries} attempts.")
                    return False
        return False

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743772051a4504551.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信