class db {
private $_pdo ,
$_query,
$_error = false,
$_results ,
$_count = 0 ;
private function __construct () {
try {
$host = config::get('mysql/host');
$database = config::get('mysql/db');
$username = config::get('mysql/user');
$pasword = config::get('mysql/password');
$this->_pdo = new PDO("mysql:host=$host;dbname=$database", $username, $pasword);
} catch (PDOException $e) {
die($e->getMessage()) ;
}
}
public static function getInstance() {
if(!isset(self::$_instance)) {
self::$_instance = new db () ;
}
return self::$_instance ;
}
public function query($sql,$params=array()) {
$this->_error = false ;
if($this->_query = $this->_pdo->prepare($sql)) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试aiohttp和asyncio第一次出现错误
[WinError 10054] 现有连接被远程主机强行关闭
但是当我获取requests它正常工作时相同的 url.so这个错误意味着什么以及如何解决它?
我的代码
import aiohttp
import asyncio
url = 'https://nseindia.com/api/historical/fo/derivatives?&from=24-01-2020&to=24-01-2020&expiryDate=06-FEB-2020&instrumentType=OPTIDX&symbol=NIFTY&csv=true'
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"}
async def get_data():
async with aiohttp.ClientSession(headers=headers) as session:
async with session.get(url) as resp:
result = await resp.text()
return result
async def main():
result = await get_data()
return result
asyncio.run(main())
Run Code Online (Sandbox Code Playgroud)