简体   繁体   English

在 python 中使用响应时,我无法从网站获得任何响应。 我收到超时错误 10060

[英]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.

相关问题 我正在尝试使用 Python 从 Excel 检索内容。 我收到投资未定义错误 - I am trying to retrieve the content from an Excel using Python. I am getting Investment undefined error 我无法在 Python 中使用 for 循环使用字符串中特定字符的索引。它给出了索引错误 - I am not able to use index of a particular character in a string using a for loop in Python. It's giving an index error 我在 Visual Studio 中的 output Python 中出现错误 - I am gettting Error in my output Python in Visual Studio 我正在尝试使用 python 从 postgressql 中的列中提取一个值。 但我总是收到这个错误: - I am trying to extract a values from column in postgressql with python. But i always get this error : 使用 pandas parse_date 时出现错误 - I am gettting an error when using pandas parse_date 我是 python 的新手。 我尝试运行一个简单的 while 循环,但收到语法错误 - I am new to python. I tried running a simple while loop but am receiving syntax error 我正在 python 中编写单元测试。 导入模块时出现此错误 - I am writing unit test in python. I am getting this error while importing my modules 我将REST API与Python结合使用。 我收到SSL错误 - I am using REST apis with Python. I am getting the a SSL error 我在python上使用Selenuim。 我需要更新两个Webelement的值,但只能更新一个 - I am using Selenuim on python. I need to update value for two Webelement but am able to only update for one 如何使用python从经典的asp网站Webscrape数据。 提交POST表单后,我无法获得结果 - How to Webscrape data from a classic asp website using python. I am having trouble getting the result after submitting the POST form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM