首页 > 解决方案 > 在 python 中使用响应时,我无法从网站获得任何响应。我收到超时错误 10060

问题描述

import requests
import pandas


def url(index, st_symbol, exp_date):
 
    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"}
    page = requests.get('https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?segmentLink=17&instrument=OPTIDX&symbol=NIFTY&date=20AUG2020', headers = headers)

error = ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))

网站- https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?segmentLink=17&instrument=OPTIDX&symbol=NIFTY&date=20AUG2020

标签: pythonresponseextract

解决方案


更改User-Agent为不同的我能够获得 HTML:

import requests

headers = {
    "User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0",
}

page = requests.get('https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?segmentLink=17&instrument=OPTIDX&symbol=NIFTY&date=20AUG2020', headers=headers)
print(page.text)

印刷:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

...

推荐阅读