У меня есть test.py
и AsyncioCurl.py
файлы.
Я запускаю python .\Src\test.pt
и выдаю мне эту ошибку.
PS C:\Users\Thinkpad\Desktop\BilibiliHelper> python .\Src\test.py
2019-02-22 10:28:27,696 - C:\Users\Thinkpad\Desktop\BilibiliHelper\Src\Log.py[line:56] - DEBUG: GET: https://api.live.bilibili.com/room/v1/area/getRoomList?platform=web&parent_area_id=4&cate_id=0&area_id=0&sort_type=online&page=1&page_size=15
2019-02-22 10:28:29,222 - C:\Users\Thinkpad\Desktop\BilibiliHelper\Src\Log.py[line:56] - DEBUG: STATUS: 200
2019-02-22 10:28:29,222 - C:\Users\Thinkpad\Desktop\BilibiliHelper\Src\Log.py[line:56] - DEBUG: <coroutine object ClientResponse.text at 0x000002C63BF24830>
C:\Users\Thinkpad\Desktop\BilibiliHelper\Src\AsyncioCurl.py:21: RuntimeWarning: coroutine 'ClientResponse.text' was never awaited
Log.debug(r.text())
Task exception was never retrieved
future: <Task finished coro=<a() done, defined at .\Src\test.py:4> exception=TimeoutError()>
Traceback (most recent call last):
File ".\Src\test.py", line 7, in a
data = await AsyncioCurl().get(url,payload)
File "C:\Users\Thinkpad\Desktop\BilibiliHelper\Src\AsyncioCurl.py", line 23, in get
return await r.json()
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\client_reqrep.py", line 1017, in json
await self.read()
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\client_reqrep.py", line 969, in read
self._body = await self.content.read()
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\streams.py", line 359, in read
block = await self.readany()
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\streams.py", line 381, in readany
await self._wait('readany')
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\streams.py", line 297, in _wait
await waiter
File "C:\Users\Thinkpad\Anaconda3\lib\site-packages\aiohttp\helpers.py", line 585, in __exit__
raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError
test.py
import asyncio
from AsyncioCurl import AsyncioCurl
async def a():
payload = {}
url = "https://api.live.bilibili.com/room/v1/area/getRoomList?platform=web&parent_area_id=4&cate_id=0&area_id=0&sort_type=online&page=1&page_size=15"
data = await AsyncioCurl().get(url,payload)
print(data)
task = [
a()
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(task))
AsyncioCurl.py
import asyncio
import aiohttp
from Log import Log
from Base import sign
from config import config
class AsyncioCurl:
def __init__(self):
self.session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=4))
async def get(self,url,param):
Log.debug("GET: "+url)
payload = {
"cookie":config["Token"]["COOKIE"]
}
payload = dict(param,**payload)
payload = sign(payload)
async with self.session.get(url,params=payload) as r:
Log.debug("STATUS: "+str(r.status))
Log.debug(r.text())
await self.session.close()
return await r.json()
async def post(self,url,param):
Log.debug("POST: "+url)
payload = {
"cookie":config["Token"]["COOKIE"]
}
payload = dict(param,**payload)
payload = sign(payload)
async with self.session.post(url,data=payload) as r:
await self.session.close()
return await r.json()
async def nspost(self,url,param):
Log.debug("POST: "+url)
headers = {
"Accept":"application/json, text/plain, */*",
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"Accept-Language":"zh-CN,zh;q=0.9",
"accept-encoding":"gzip, deflate",
"cookie":config["Token"]["COOKIE"]
}
async with self.session.post(url,data=param,headers=headers) as r:
await self.session.close()
return await r.json()
async def nsdpost(self,url):
Log.debug("POST: "+url)
headers = {
"Accept":"application/json, text/plain, */*",
"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"Accept-Language":"zh-CN,zh;q=0.9",
"accept-encoding":"gzip, deflate",
"cookie":config["Token"]["COOKIE"]
}
async with self.session.post(url,headers=headers) as r:
return await r.json()
PS: прямой доступ к этомуна сайте нет ошибок.