requests-html HTTPSConnectionPoolRead timed out

若如初见. 提交于 2020-01-16 13:31:45

问题


Trying to send a request to here using requests-html.

Here is my code:

headers = {"User-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"}
session = HTMLSession()
while True:
   try:
       r = session.get("https://www.size.co.uk/product/white-fila-v94m-low/119095/",headers=headers,timeout=40)
       r.html.render()
       print(r.html.text)

   except Exception as e:
       print(e)

Here is the error I am receiving:

HTTPSConnectionPool(host='www.size.co.uk', port=443): Read timed out. (read timeout=40)

I thought setting the user agent would fix the problem, but I am still receiving the error? Increasing the timeout hasn't done the trick either


回答1:


You can do this with Async

from requests_html import AsyncHTMLSession

s = AsyncHTMLSession()
async def main():
    r = await s.get('https://www.size.co.uk/product/white-fila-v94m-low/119095/')
    await r.html.arender()
    print(r.content)

s.run(main)


来源:https://stackoverflow.com/questions/56691190/requests-html-httpsconnectionpoolread-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!