[英]i am not able to get any response from the website while using response in python. I am gettting a time out error 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')")) error = ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))
website - https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?segmentLink=17&instrument=OPTIDX&symbol=NIFTY&date=20AUG2020网站-https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?segmentLink=17&instrument=OPTIDX&symbol20=20G&date=20G
Changing the User-Agent
to different one I was able to get the HTML:将
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)
Prints:印刷:
<!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>
...
10060
seems to be an error coming from low-latency connections.
10060
似乎是来自low-latency connections.
From sources, the best fix is to either speed-up your connection by disabling any downloads
you may be having or by adding timeouts
to your connection(s) this can be done in many ways depending on how you're trying to access the remote hosts.从消息来源来看,最好的解决方法是通过禁用您可能拥有的任何
downloads
或通过为您的连接添加timeouts
来加速您的连接,这可以通过多种方式完成,具体取决于您尝试访问远程的方式主机。
Luckily, the requests library got that ability: Your code should look like this:幸运的是,requests 库具有这种能力:您的代码应如下所示:
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', timeout=0.001, headers=headers) # Timeout can be any value, format: <second>.<milisecond>
Documentation for Error 10060: 10060 Connection Error错误 10060 的文档: 10060 连接错误
Documentation for Timeouts: Quickstart - Requests.Timeouts超时文档: 快速入门 - Requests.Timeouts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.