最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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
发布评论

评论列表(0)

  1. 暂无评论