解决SSL问题:WRONG_VERSION_NUMBER

时间:2019-06-07 14:13:14

标签: python asynchronous aiohttp

我正在尝试使用asyncio和aiohttp创建一个程序来测试我网站的某些功能,例如填写表格和收集cookie。我正在使用代理进行测试,只是让它访问我的页面并检查是否在HTML中放置了某些内容,但是我不断收到诸如以下的错误:

15:01:29.600 SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x0873A0B0>
transport: <_SelectorSocketTransport fd=1492 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\asyncio\sslproto.py", line 207, in feed_ssldata
    self._sslobj.unwrap()
  File "C:\Users\x\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 767, in unwrap
    return self._sslobj.shutdown()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2609)

并不是我启动的每个实例都会发生这种情况,但是很多情况都会发生。这是我的代码

import asyncio
import ClientSession from aiohttp

def main():
    tasks = []
    loop = asyncio.get_event_loop()
    for i in range(10):
        task = asyncio.ensure_future(launch(url, ip, port))
        tasks.append(task)
    loop.run_until_complete(asyncio.wait(tasks))


async def launch(url, ip, port):
    done = False
    proxy = "http://{}:{}".format(ip, port)
    async with ClientSession() as session:
        while not done:
            async with session.get(url, timeout=40, proxy=proxy) as initial:
                html_text = await initial.text()
                if x in html_text:
                    done = True
                else:
                    asyncio.sleep(60)
        await session.close()

if __name__ == "__main__":
    main()

代理就是HTTP代理。

如果有人可以帮助我解决这个问题,那将非常有用,谢谢。

编辑:如果有帮助,我的网站是HTTPS。

EDIT2:为进一步澄清,它们都工作了一段时间并保持刷新,但随后它们都开始一个个地死掉

EDIT3:打印所有错误后,我也收到此错误:

Cannot connect to host domain:[prt ssl:None [Connect call failed ('IP', Port)]

0 个答案:

没有答案