question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client_session: <aiohttp.client.ClientSession object at 0x000001B7CD7F9B70>

See original GitHub issue

I can get the ticker when I use the first code, but when I use async , the code run wrong, how to slove it ! can you help me? I am use python 3.6 on windows 10 .

the first code:

import ccxt
exchange = ccxt.binance()
symbol = 'BTC/USDT'
ticker = exchange.fetch_ticker(symbol)
print(ticker)

image

the sencond code:

import asyncio
import ccxt.async as ccxt

async def getticker():
    binance = ccxt.binance()
    print(await binance.fetch_ticker('BTC/USDT'))

asyncio.get_event_loop().run_until_complete(getticker())
Traceback (most recent call last):
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 124, in fetch
    proxy=self.aiohttp_proxy) as response:
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\client.py", line 690, in __aenter__
    self._resp = yield from self._coro
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\client.py", line 341, in _request
    break
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\helpers.py", line 727, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/python3/test/test.py", line 10, in <module>
    asyncio.get_event_loop().run_until_complete(getticker())
  File "C:\Users\SXY004\Anaconda3\lib\asyncio\base_events.py", line 466, in run_until_complete
    return future.result()
  File "E:/python3/test/test.py", line 8, in getticker
    print(await binance.fetch_ticker('BTC/USDT'))
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\binance.py", line 492, in fetch_ticker
    await self.load_markets()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 153, in load_markets
    markets = await self.fetch_markets()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\binance.py", line 345, in fetch_markets
    response = await self.publicGetExchangeInfo()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 102, in fetch2
    return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 139, in fetch
    self.raise_error(RequestTimeout, method, url, e, None)
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 274, in raise_error
    raise exception_type(output)
ccxt.base.errors.RequestTimeout: binance GET https://api.binance.com/api/v1/exchangeInfo 
binance requires to release all resources with an explicit call to the .close() coroutine.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001AE4AB39B00>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:30 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Mar 22, 2018

@zhoujinhai, @cmosse see the answer here:

https://github.com/ccxt/ccxt/issues/2324#issuecomment-374968303

# -*- coding: utf-8 -*-

import asyncio
import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt.async as ccxt  # noqa: E402


async def test_gdax():
    gdax = ccxt.gdax()
    markets = await gdax.load_markets()
    await gdax.close()
    return markets

if __name__ == '__main__':  # added this check
    print(asyncio.get_event_loop().run_until_complete(test_gdax()))

Hope it helps.

1reaction
frosty00commented, Mar 21, 2018

have you tried:

async def getticker():
    binance = ccxt.binance({'asyncio_loop': asyncio.get_event_loop()})

or just setting the event loop at the top and always using that loop?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client Reference — aiohttp 3.8.3 documentation
Client session is the recommended interface for making HTTP requests. ... BasicAuth) – an object that represents HTTP Basic Authorization (optional).
Read more >
aiohttp: Unclosed client session client_session - Stack Overflow
It's not an error, just a warning. And you can deal with it by closing the session. Try this: async def a(): payload...
Read more >
aiohttp-client-manager 1.1.2 - PyPI
Project description. A module to automatically manage aiohttp.ClientSession objects for you to improve performance. The package manages a global cache of ...
Read more >
aiohttp Client
Client class¶. Client is a class with embedded aiohttp.ClientSession . Also, we need the REST server URL to connect ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found