上面的url是get请求url,下面是我的python代码
import requests
url = "https://www.nseindia.com/api/corporates-pit?index=equities&from_date=21-04-2020&to_date=21-07-2020&csv=true"
payload = {}
headers= {}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
我还尝试了http.client
import http.client
import mimetypes
conn = http.client.HTTPSConnection("www.nseindia.com")
payload = ''
headers = {}
conn.request("GET", "/api/corporates-pit?index=equities&from_date=21-04-2020&to_date=21-07-2020&csv=true", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
错误/秒
urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
During handling of the above exception, another exception occurred:
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
更新代码
请在下面找到代码的工作版本。您需要将
agent
和cookies
变量传递给requests
相关问题 更多 >
编程相关推荐