aiohttp 用代理IP访问提示‘NoneType‘ object has no attribute ‘get_extra_info‘

项目场景:

aiohttp 用代理IP访问提示 ‘NoneType’ object has no attribute ‘get_extra_info’


问题描述

# 定义异步函数,用于发送请求并获取结果
async def fetch(url, session, proxy, headers):
    # 代理服务器的URL,格式为http://hostname:port
    #proxy_url = 'http://username:password@proxy_address:proxy_port'
    proxy_h1 = 'http://' + str(proxy['username']) + ':' + str(proxy['pwd']) + '@' + str(proxy['ip']) + ':' + str(proxy['port'])
    print(proxy_h1,'proxy_h1proxy_h1proxy_h1')
    async with session.get(url, proxy=proxy_h1, headers=headers) as response:
        return await response.text()


# 定义异步函数,用于并发请求
async def main(urls, proxies, headers):
    timeout = aiohttp.ClientTimeout(total=180)
    connector = aiohttp.TCPConnector(limit=50 ,verify_ssl=False)
    async with aiohttp.ClientSession(connector=connector, timeout=timeout, trust_env=True) as session:
        tasks = [fetch(url, session, proxy, headers) for url, proxy in zip(urls, proxies)]
        results = await asyncio.gather(*tasks)
        # print(results,'resultsresultsresultsresults')
        return results

原因分析:

试了半天发现是python aiohttp 源码有问题

解决方案:

python目录下/Lib\site-packages\aiohttp\ 找到 connector.py

 # 注释如下行
 #runtime_has_start_tls = self._loop_supports_start_tls()
# 新增
 runtime_has_start_tls = False if req.proxy.scheme != "https" else self._loop_supports_start_tls()

ok 访问正常

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]和\[2\]中提到的错误信息"AttributeError: 'NoneType' object has no attribute 'get_fetch_list'"是由于在使用PaddlePaddle框架时出现的问题。这个错误通常是由于没有正确设置PaddlePaddle的执行环境所导致的。在引用\[2\]中的代码中,通过添加"paddle.enable_static()"这一句来解决了这个问题。这个函数的作用是启用静态图模式,它会将动态图模式切换为静态图模式,从而解决了该错误。 另外,引用\[3\]中提到的错误信息"AttributeError: type object 'Chinese' has no attribute '__int__'"是由于在使用Python时出现的问题。这个错误通常是由于尝试将一个自定义的类作为整数类型使用,但该类没有实现"__int__"方法所导致的。要解决这个问题,需要在自定义类中实现"__int__"方法,以便正确地将该类转换为整数类型。 综上所述,要解决这两个错误,可以通过添加"paddle.enable_static()"来解决PaddlePaddle框架中的错误,而在Python中的错误则需要在自定义类中实现"__int__"方法。 #### 引用[.reference_title] - *1* *2* *3* [Paddle AttributeError: ‘NoneTypeobject has no attribute ‘get_fetch_list‘问题何在](https://blog.csdn.net/alston_ethannical/article/details/120105223)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值